|
1 "{ Package: 'stx:goodies/ston/tests' }" |
|
2 |
|
3 "{ NameSpace: Smalltalk }" |
|
4 |
|
5 TestCase subclass:#STONCStyleCommentsSkipStreamTests |
|
6 instanceVariableNames:'' |
|
7 classVariableNames:'' |
|
8 poolDictionaries:'' |
|
9 category:'STON-Tests-Reader' |
|
10 ! |
|
11 |
|
12 !STONCStyleCommentsSkipStreamTests methodsFor:'testing'! |
|
13 |
|
14 testBlockReading |
|
15 | input buffer | |
|
16 input := STONCStyleCommentsSkipStream on: 'abc/*comment*/def' readStream. |
|
17 buffer := String new: 6. |
|
18 self assert: (input readInto: buffer startingAt: 1 count: 4) equals: 4. |
|
19 self assert: (buffer copyFrom: 1 to: 4) equals: 'abcd'. |
|
20 self assert: (input readInto: buffer startingAt: 5 count: 4) equals: 2. |
|
21 self assert: buffer equals: 'abcdef'. |
|
22 input := STONCStyleCommentsSkipStream on: 'abc//comment\def' withCRs readStream. |
|
23 buffer := String new: 6. |
|
24 self assert: (input readInto: buffer startingAt: 1 count: 6) equals: 6. |
|
25 self assert: buffer equals: 'abcdef'. |
|
26 self assert: input atEnd |
|
27 ! |
|
28 |
|
29 testCommentInString |
|
30 self |
|
31 assert: (STONCStyleCommentsSkipStream on: '''/*comment*/''' readStream) upToEnd |
|
32 equals: '''/*comment*/'''. |
|
33 self |
|
34 assert: (STONCStyleCommentsSkipStream on: '{''foo'':''/*comment*/bar''}' readStream) upToEnd |
|
35 equals: '{''foo'':''/*comment*/bar''}'. |
|
36 self |
|
37 assert: (STONCStyleCommentsSkipStream on: '{''foo'':''//comment\''bar''}' readStream) upToEnd |
|
38 equals: '{''foo'':''//comment\''bar''}'. |
|
39 self |
|
40 assert: (STONCStyleCommentsSkipStream on: '{"foo":"/*comment*/bar"}' readStream) upToEnd |
|
41 equals: '{"foo":"/*comment*/bar"}'. |
|
42 self |
|
43 assert: (STONCStyleCommentsSkipStream on: '{"foo":"//comment\"bar"}' readStream) upToEnd |
|
44 equals: '{"foo":"//comment\"bar"}' |
|
45 ! |
|
46 |
|
47 testMultiLineComment |
|
48 self |
|
49 assert: (STONCStyleCommentsSkipStream on: 'foo\//comment\bar' withCRs readStream) upToEnd |
|
50 equals: 'foo\bar' withCRs. |
|
51 self |
|
52 assert: (STONCStyleCommentsSkipStream on: 'foo\//comment\bar' withCRs readStream) nextLine |
|
53 equals: 'foo'. |
|
54 self |
|
55 assert: ((STONCStyleCommentsSkipStream on: 'foo\//comment\bar' withCRs readStream) nextLine; nextLine) |
|
56 equals: 'bar'. |
|
57 self assert: (STONCStyleCommentsSkipStream on: '//comment' readStream) atEnd. |
|
58 ! |
|
59 |
|
60 testNonComment |
|
61 self assert: (STONCStyleCommentsSkipStream on: 'foo' readStream) upToEnd equals: 'foo'. |
|
62 self assert: (STONCStyleCommentsSkipStream on: 'foo' readStream) nextLine equals: 'foo'. |
|
63 self deny: (STONCStyleCommentsSkipStream on: 'foo' readStream) atEnd. |
|
64 self assert: (STONCStyleCommentsSkipStream on: '' readStream) atEnd. |
|
65 ! |
|
66 |
|
67 testSTON |
|
68 "Comments are processed first and totally removed. |
|
69 They are not even whitespace (not that whitespace is relevant in STON)." |
|
70 |
|
71 self |
|
72 assert: (STON fromStream: (STONCStyleCommentsSkipStream on: '123/*comment*/456' readStream)) |
|
73 equals: 123456. |
|
74 self |
|
75 assert: (STON fromStream: (STONCStyleCommentsSkipStream on: '/*comment*/''abcd''' readStream)) |
|
76 equals: 'abcd'. |
|
77 self |
|
78 assert: (STON fromStream: (STONCStyleCommentsSkipStream on: '123//456' readStream)) |
|
79 equals: 123. |
|
80 self |
|
81 should: [ STON fromStream: (STONCStyleCommentsSkipStream on: '//456' readStream) ] |
|
82 raise: STONReaderError |
|
83 ! |
|
84 |
|
85 testSingleLineComment |
|
86 self assert: (STONCStyleCommentsSkipStream on: 'foo/*comment*/bar' readStream) upToEnd equals: 'foobar'. |
|
87 self assert: (STONCStyleCommentsSkipStream on: 'foo/*comment*/bar' readStream) nextLine equals: 'foobar'. |
|
88 self deny: (STONCStyleCommentsSkipStream on: 'foo/*comment*/bar' readStream) atEnd. |
|
89 self assert: (STONCStyleCommentsSkipStream on: '/*comment*/' readStream) atEnd. |
|
90 ! ! |
|
91 |