[svn] r7814: nemerle/trunk/ncc/testsuite: . positive/string-template.n

VladD2 svnadmin at nemerle.org
Thu Oct 18 14:26:53 CEST 2007


Log:
Add test for NemerleStringTemplate.

Author: VladD2
Date: Thu Oct 18 14:26:52 2007
New Revision: 7814

Added:
   nemerle/trunk/ncc/testsuite/positive/string-template.n
Modified:
   nemerle/trunk/ncc/testsuite/   (props changed)

Added: nemerle/trunk/ncc/testsuite/positive/string-template.n
==============================================================================
--- (empty file)
+++ nemerle/trunk/ncc/testsuite/positive/string-template.n	Thu Oct 18 14:26:52 2007
@@ -0,0 +1,118 @@
+using System;
+using Nemerle.Collections;
+using System.Console;
+using Nemerle.Utility;
+using StringTemplate;
+using System.Diagnostics;
+using SCG = System.Collections.Generic;
+
+[Record]
+public class Index
+{
+  public Name      : string;
+  public Entries   : list[IndexEntry];
+}
+
+[Record]
+public class IndexEntry
+{
+  public Name        : string;
+  public IsDescend   : bool;
+}
+
+[StringTemplateGroup]
+public class MyTemplateGroup
+{
+  Values : list[string] = ["<Test1>", "<Test2>"];
+  Value : string = "<Test3>#\n<Test4>#";
+  
+  Batch(indexs : list[Index]) : string {<#
+  BEGIN TRAN
+    ..$(indexs; "\ngo\n\n"; CreateIndex)
+    go
+  COMMIT TRAN
+  #>}
+  
+  CreateIndex(index : Index) : string {<#
+..CREATE INDEX $(index.Name)
+..(
+..  ..$(index.Entries; ",\n"; IndxEntry)
+..  {
+..    $(TestNewLine())
+..    ..$(Values; ";\n");
+..    $Value
+..  }
+..)
+..#>}
+
+  static TestNewLine() : string
+  {
+    def x = "QQQ\nGGG";
+    x
+  }
+
+  IndxEntry(entry : IndexEntry) : string {<#
+  $(entry.Name)$(Descend(entry))
+  #>}
+  
+  Descend(entry : IndexEntry) : string { if (entry.IsDescend) " DESC" else "" }
+  
+  public Test1() : void { }
+  public Test2() : int { 0 }
+} 
+
+module Program
+{
+  Main() : void
+  {
+    def indexs = [
+      Index("MyIndex1", [IndexEntry("Col1", false), IndexEntry("Col2", true)]),
+      Index("MyIndex2", [IndexEntry("Column2", false), IndexEntry("Col3", false)]),
+      ];
+    System.Console.BackgroundColor = ConsoleColor.DarkCyan;
+    def res = MyTemplateGroup.Batch(indexs);
+    Write(res);
+    System.Console.ResetColor();
+
+    WriteLine();
+    Write("...");
+    // _ = ReadLine();
+  }
+}
+
+/*
+BEGIN-OUTPUT
+BEGIN TRAN
+  CREATE INDEX MyIndex1
+  (
+    Col1,
+    Col2 DESC
+    {
+      QQQ
+      GGG
+      <Test1>;
+      <Test2>;
+      <Test3>#
+      <Test4>#
+    }
+  )
+  go
+
+  CREATE INDEX MyIndex2
+  (
+    Column2,
+    Col3
+    {
+      QQQ
+      GGG
+      <Test1>;
+      <Test2>;
+      <Test3>#
+      <Test4>#
+    }
+  )
+  go
+COMMIT TRAN
+...
+END-OUTPUT
+*/ 
\ No newline at end of file



More information about the svn mailing list