Fix for the Syntax tests file.
[cslatevm.git] / tests / syntax.slate
blob822c88fb9ef7fc6cb598f3a05a4108e8c6401e62
1 UnitTests addPrototype: #Syntax derivedFrom: {TestCase}.
2 "Test the Slate parser"
4 UnitTests Syntax addSlot: #inputFileName valued: ('src/syntax/writer.slate' as: File Locator).
6 t@(UnitTests Syntax traits) parseFile: file into: statements
8   file sessionDo:
9     [| :input | (Syntax Parser newOn: input reader) >> statements writer] &mode: File Read.
10   t
13 t@(UnitTests Syntax traits) countStatements: statements
14 [| count |
15   count: 0.
16   statements do: [| :statement |
17           count: count + 1.
18                     statement walk: [| :node | count: count + 1]].
19   count
22 t@(UnitTests Syntax traits) writeStatements: statements into: buffer
24   statements do: [| :statement | (Syntax SourceWriter newOn: buffer) print: statement]
25              separatedBy: [buffer ; '.\n'].
26   t
29 t@(UnitTests Syntax traits) testParsingAndWriting
30 [ | originalStatements originalCount buffer1 statements1 count1 buffer2 statements2 count2 |
31   originalStatements: ExtensibleArray new.
32   statements1: ExtensibleArray new.
33   statements2: ExtensibleArray new.
34   buffer1: '' writer.
35   buffer2: '' writer.
37   "Parse original file"
38   t parseFile: t inputFileName into: originalStatements.
39   originalCount: (t countStatements: originalStatements).
40   t writeStatements: originalStatements into: buffer1.
42   "Parse output of the first write"
43   (Syntax Parser newOn: buffer1 contents reader) >> statements1 writer.
44   count1: (t countStatements: statements1).
45   t writeStatements: statements1 into: buffer2.
47   "Parse output of second write"
48   (Syntax Parser newOn: buffer2 contents reader) >> statements2 writer.
49   count2: (t countStatements: statements2).
51   t assert: count1 = count2 description: ('Statement count mismatch after parsing writer output: ' ; (count1 as: String) ; ' ~= ' ; (count2 as: String)).
52   t assert: buffer1 contents = buffer2 contents description: 'Buffer contents mismatch'.
56 t@(UnitTests Syntax traits) suite
57 [t suiteForSelectors: {
58   #testParsingAndWriting.
59 }].