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
9 [| :input | (Syntax Parser newOn: input reader) >> statements writer] &mode: File Read.
13 t@(UnitTests Syntax traits) countStatements: statements
16 statements do: [| :statement |
18 statement walk: [| :node | count: count + 1]].
22 t@(UnitTests Syntax traits) writeStatements: statements into: buffer
24 statements do: [| :statement | (Syntax SourceWriter newOn: buffer) print: statement]
25 separatedBy: [buffer ; '.\n'].
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.
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.