wneuper@5130
|
1 |
package isac.gui.mawen.scalaterm;
|
wneuper@5130
|
2 |
|
wneuper@5130
|
3 |
import isac.bridge.Isabelle_Isac
|
wneuper@5130
|
4 |
import isac.bridge.xml.DataTypes
|
walther@5239
|
5 |
import edu.tum.cs.isabelle.pure._ // for Term
|
walther@5239
|
6 |
import edu.tum.cs.isabelle._ // for Codec
|
walther@5239
|
7 |
import edu.tum.cs.isabelle.japi._ // for JSystem
|
wneuper@5130
|
8 |
|
wneuper@5130
|
9 |
import junit.framework.TestCase
|
wneuper@5130
|
10 |
import org.junit.Assert._
|
wneuper@5130
|
11 |
|
wneuper@5130
|
12 |
/**
|
wneuper@5130
|
13 |
* Create libisabelle's Scala Term from String for tests.
|
wneuper@5130
|
14 |
* Compare ScalaAstFromString.
|
wneuper@5130
|
15 |
*/
|
wneuper@5130
|
16 |
class ScalaTermFromString extends TestCase {
|
wneuper@5130
|
17 |
|
wneuper@5150
|
18 |
var sys_ : JSystem = null
|
wneuper@5150
|
19 |
override def setUp() {
|
wneuper@5150
|
20 |
sys_ = Isabelle_Isac.connect();
|
wneuper@5150
|
21 |
}
|
wneuper@5130
|
22 |
|
wneuper@5130
|
23 |
/**
|
wneuper@5130
|
24 |
* test output from ~~/src/Tools/isac/ProgLang/termC.sml: scala_of_term
|
wneuper@5130
|
25 |
*/
|
wneuper@5130
|
26 |
def test_scala_of_term() {
|
wneuper@5130
|
27 |
println("/--BEGIN isac.gui.mawen.TestUseCases#test_scala_of_term");
|
wneuper@5130
|
28 |
|
wneuper@5130
|
29 |
var term_str = "aaa"
|
wneuper@5130
|
30 |
var tree = sys_.invoke(isac.bridge.IsacOperations.SCALATERM_OF_STRING, term_str)
|
wneuper@5130
|
31 |
var term = DataTypes.xml_to_Term(tree)
|
wneuper@5130
|
32 |
assertEquals(term,
|
wneuper@5130
|
33 |
// copied output from ~~/src/Tools/isac/ProgLang/termC.sml: scala_of_term
|
wneuper@5130
|
34 |
Free("aaa", TFree("'a", List()))
|
wneuper@5130
|
35 |
)
|
wneuper@5130
|
36 |
|
wneuper@5130
|
37 |
term_str = "let aaa = bbb in aaa"
|
wneuper@5130
|
38 |
tree = sys_.invoke(isac.bridge.IsacOperations.SCALATERM_OF_STRING, term_str)
|
wneuper@5130
|
39 |
term = DataTypes.xml_to_Term(tree)
|
wneuper@5130
|
40 |
assertEquals(term,
|
wneuper@5130
|
41 |
// copied output from ~~/src/Tools/isac/ProgLang/termC.sml: scala_of_term
|
wneuper@5130
|
42 |
App(App(Const("HOL.Let", Type("fun", List(TFree("'a", List("HOL.type")),Type("fun", List(Type("fun", List(TFree("'a", List("HOL.type")),TFree("'a", List("HOL.type")))),TFree("'a", List("HOL.type"))))))), Free("bbb", TFree("'a", List("HOL.type")))), Abs("aaa", TFree("'a", List("HOL.type")), Bound(0)))
|
wneuper@5130
|
43 |
)
|
wneuper@5130
|
44 |
|
wneuper@5130
|
45 |
// ATTENTION: numerals are different due to specific Isac code:
|
wneuper@5130
|
46 |
// ~~/src/Tools/isac/ProgLang/termC.sml: numbers_to_string
|
wneuper@5130
|
47 |
term_str = "0"
|
wneuper@5130
|
48 |
tree = sys_.invoke(isac.bridge.IsacOperations.SCALATERM_OF_STRING, term_str)
|
wneuper@5130
|
49 |
term = DataTypes.xml_to_Term(tree)
|
wneuper@5130
|
50 |
assertEquals(term,
|
wneuper@5130
|
51 |
// NOT copied:
|
wneuper@5130
|
52 |
Free("0", TFree("'a", List("Groups.zero")))
|
wneuper@5130
|
53 |
)
|
wneuper@5130
|
54 |
// copied output from ~~/src/Tools/isac/ProgLang/termC.sml: scala_of_term (without parse*)
|
wneuper@5130
|
55 |
Const("Groups.zero_class.zero", TFree("'a", List("Groups.zero")))
|
wneuper@5130
|
56 |
|
wneuper@5130
|
57 |
println("\\--END isac.gui.mawen.TestUseCases#test_scala_of_term");
|
wneuper@5130
|
58 |
}
|
wneuper@5130
|
59 |
|
wneuper@5137
|
60 |
def test_etc() {
|
wneuper@5137
|
61 |
println("/--BEGIN isac.gui.mawen.syntax.ScalaAstFromString#test_etc");
|
wneuper@5137
|
62 |
|
wneuper@5137
|
63 |
//dummy
|
wneuper@5137
|
64 |
var term_str = "dummy"
|
wneuper@5137
|
65 |
var tree = sys_.invoke(isac.bridge.IsacOperations.SCALATERM_OF_STRING, term_str)
|
wneuper@5137
|
66 |
var term = DataTypes.xml_to_Term(tree)
|
wneuper@5137
|
67 |
|
wneuper@5137
|
68 |
term_str = "(aaa, bbb, ccc, ddd)"
|
wneuper@5137
|
69 |
tree = sys_.invoke(isac.bridge.IsacOperations.SCALATERM_OF_STRING, term_str)
|
wneuper@5137
|
70 |
term = DataTypes.xml_to_Term(tree)
|
wneuper@5137
|
71 |
assertEquals(term,
|
wneuper@5137
|
72 |
// copied output from SML: writeln(scala_of_term(@{term "(aaa, bbb, ccc)"}))
|
wneuper@5137
|
73 |
App(
|
wneuper@5137
|
74 |
App(
|
wneuper@5137
|
75 |
Const("Product_Type.Pair", Type("fun", List(TFree("'a", List("HOL.type")),Type("fun", List(Type("Product_Type.prod", List(TFree("'b", List("HOL.type")),Type("Product_Type.prod", List(TFree("'c", List("HOL.type")),TFree("'d", List("HOL.type")))))),Type("Product_Type.prod", List(TFree("'a", List("HOL.type")),Type("Product_Type.prod", List(TFree("'b", List("HOL.type")),Type("Product_Type.prod", List(TFree("'c", List("HOL.type")),TFree("'d", List("HOL.type"))))))))))))),
|
wneuper@5137
|
76 |
Free("aaa", TFree("'a", List("HOL.type")))),
|
wneuper@5137
|
77 |
App(
|
wneuper@5137
|
78 |
App(
|
wneuper@5137
|
79 |
Const("Product_Type.Pair", Type("fun", List(TFree("'b", List("HOL.type")),Type("fun", List(Type("Product_Type.prod", List(TFree("'c", List("HOL.type")),TFree("'d", List("HOL.type")))),Type("Product_Type.prod", List(TFree("'b", List("HOL.type")),Type("Product_Type.prod", List(TFree("'c", List("HOL.type")),TFree("'d", List("HOL.type"))))))))))),
|
wneuper@5137
|
80 |
Free("bbb", TFree("'b", List("HOL.type")))),
|
wneuper@5137
|
81 |
App(
|
wneuper@5137
|
82 |
App(
|
wneuper@5137
|
83 |
Const("Product_Type.Pair", Type("fun", List(TFree("'c", List("HOL.type")),Type("fun", List(TFree("'d", List("HOL.type")),Type("Product_Type.prod", List(TFree("'c", List("HOL.type")),TFree("'d", List("HOL.type"))))))))),
|
wneuper@5137
|
84 |
Free("ccc", TFree("'c", List("HOL.type")))),
|
wneuper@5137
|
85 |
Free("ddd", TFree("'d", List("HOL.type"))
|
wneuper@5137
|
86 |
))
|
wneuper@5137
|
87 |
))
|
wneuper@5137
|
88 |
)
|
wneuper@5137
|
89 |
println("\\--END isac.gui.mawen.syntax.ScalaAstFromString#test_etc");
|
wneuper@5137
|
90 |
}
|
wneuper@5137
|
91 |
|
wneuper@5150
|
92 |
override def tearDown() {
|
wneuper@5150
|
93 |
sys_.dispose()
|
wneuper@5150
|
94 |
super.tearDown()
|
wneuper@5150
|
95 |
}
|
walther@5239
|
96 |
}
|