islands/tests/PPIslandTest.st
changeset 387 e2b2ccaa4de6
child 389 009c2e13973c
equal deleted inserted replaced
386:a409905f7f2d 387:e2b2ccaa4de6
       
     1 "{ Package: 'stx:goodies/petitparser/islands/tests' }"
       
     2 
       
     3 PPAbstractParserTest subclass:#PPIslandTest
       
     4 	instanceVariableNames:'result context'
       
     5 	classVariableNames:''
       
     6 	poolDictionaries:''
       
     7 	category:'PetitIslands-Tests'
       
     8 !
       
     9 
       
    10 PPIslandTest comment:''
       
    11 !
       
    12 
       
    13 !PPIslandTest methodsFor:'as yet unclassified'!
       
    14 
       
    15 context
       
    16 	context ifNil: [ ^ super context ].
       
    17 	^ context
       
    18 !
       
    19 
       
    20 setUp
       
    21 	super setUp.
       
    22 	context := nil
       
    23 ! !
       
    24 
       
    25 !PPIslandTest methodsFor:'parse support'!
       
    26 
       
    27 identifier 
       
    28  	^ ((#letter asParser / $# asParser), (#letter asParser / #digit asParser) star) flatten 
       
    29 !
       
    30 
       
    31 island: parser
       
    32 	^ self islandInstance island: parser.
       
    33 !
       
    34 
       
    35 island: parser water: water
       
    36 	^ self islandInstance 
       
    37 		island: parser;
       
    38 		water: water;
       
    39 		yourself
       
    40 	
       
    41 !
       
    42 
       
    43 islandClass 
       
    44 	^ PPIsland  
       
    45 !
       
    46 
       
    47 islandInstance
       
    48 	^ self islandClass new 
       
    49 !
       
    50 
       
    51 nestedBlock
       
    52 	| blockIsland block nilIsland |
       
    53 	blockIsland := self islandInstance.
       
    54 	nilIsland := self nilIsland.
       
    55 	
       
    56 	block := PPDelegateParser new.
       
    57 	block setParser: (${ asParser,  (blockIsland plus / nilIsland), $} asParser).
       
    58 	block name: 'block'.
       
    59 	
       
    60 	blockIsland island: block.
       
    61 	blockIsland name: 'block island'.
       
    62 	^ block
       
    63 !
       
    64 
       
    65 nilIsland
       
    66 	|  nilIsland |
       
    67 	nilIsland := self islandInstance.
       
    68 	
       
    69 	nilIsland island: nil asParser.
       
    70 	nilIsland name: 'nil island'.
       
    71 	
       
    72 	^ nilIsland
       
    73 ! !
       
    74 
       
    75 !PPIslandTest methodsFor:'parsing'!
       
    76 
       
    77 assert: parser parse: input
       
    78 	result := super assert: parser parse: input
       
    79 ! !
       
    80 
       
    81 !PPIslandTest methodsFor:'testing'!
       
    82 
       
    83 testBlock
       
    84 	| block  |
       
    85 
       
    86 	block := self nestedBlock.
       
    87 	
       
    88 	self assert: block parse: '{}'.
       
    89 	self assert: result size = 3.
       
    90 	self assert: result first = ${.
       
    91 	self assert: result third = $}.
       
    92 	
       
    93 	self assert: block parse: '{ }'.
       
    94 	self assert: result size = 3.
       
    95 	self assert: result first = ${.
       
    96 	self assert: result third = $}.	
       
    97 		
       
    98 	self assert: block parse: '{ { } }'.
       
    99 	self assert: result size = 3.
       
   100 	self assert: result first = ${.
       
   101 	self assert: result third = $}.	
       
   102 		
       
   103 		
       
   104 	self assert: block parse: '{ { {{} } } }'.
       
   105 	self assert: result isCollection.
       
   106 	self assert: result  size = 3.
       
   107 	self assert: result  first = ${.
       
   108 	self assert: result  second first second first = ${.
       
   109 	self assert: result  second first second second first second first = ${.
       
   110 	self assert: result  second first second second first second third = $}.
       
   111 	self assert: result  second first second third = $}.	
       
   112 	self assert: result  third = $}.
       
   113 	
       
   114 	
       
   115 	self assert: block parse: '{ { 
       
   116 		{{} } 
       
   117 	} }'.
       
   118 	self assert: result isCollection.
       
   119 	self assert: result  size = 3.
       
   120 	self assert: result  first = ${.
       
   121 	self assert: result  second first second first = ${.
       
   122 	self assert: result  second first second second first second first = ${.
       
   123 	self assert: result  second first second second first second third = $}.
       
   124 	self assert: result  second first second third = $}.	
       
   125 	self assert: result  third = $}.				
       
   126 !
       
   127 
       
   128 testBoundary
       
   129 	|  p end body start |
       
   130 	
       
   131 	"use non-trivial end-of-class a complex end"
       
   132 	end := 'end' asParser trimBlanks, 'of' asParser trimBlanks, 'class' asParser trimBlanks ==> [:args | #eoc].
       
   133 	body := self nilIsland.
       
   134 	start := 'class' asParser trim, self identifier.
       
   135 	p := start, body, end.
       
   136 	
       
   137 	self assert: p parse: 'class Foo end of class'.
       
   138 	self assert: result size = 4.
       
   139 	self assert: result second = 'Foo'.
       
   140 	
       
   141 	self assert: p parse: 'class Foo .... end of class'.
       
   142 	self assert: result size = 4.
       
   143 	self assert: result second = 'Foo'.
       
   144 	
       
   145 	self assert: p parse: 'class Foo .... end ... end of class'.
       
   146 	self assert: result size = 4.
       
   147 	self assert: result second = 'Foo'.
       
   148 	
       
   149 	self assert: p parse: 'class Foo .... end of ... end of class'.
       
   150 	self assert: result size = 4.
       
   151 	self assert: result second = 'Foo'.
       
   152 !
       
   153 
       
   154 testBoundary2
       
   155 	
       
   156 	|   epilog  id p |
       
   157 	"use optional boundary"
       
   158 	epilog := 'end' asParser optional.
       
   159 	id := self identifier.
       
   160 	p := ((self island: id), epilog) plus.
       
   161 
       
   162 	self assert: p parse: '...foo..end...bar...end'.	
       
   163 	
       
   164 	self assert: result first first second = 'foo'.
       
   165 	self assert: result first second = 'end'.
       
   166 
       
   167 	self assert: result second first second = 'bar'.
       
   168 	self assert: result second second = 'end'.
       
   169 !
       
   170 
       
   171 testIslandAfterIslandPlus
       
   172 	
       
   173 	| island2 islandParser2 island1 islandParser1 parser |
       
   174 	island1 := 'aa' asParser, 'bb' asParser.
       
   175 	islandParser1 := self islandInstance.
       
   176 	islandParser1 island: island1.
       
   177 	
       
   178 	island2 := 'cc' asParser.
       
   179 	islandParser2 := self islandInstance.
       
   180 	islandParser2 island: island2.
       
   181 	
       
   182 	parser := (islandParser1, islandParser2) plus.
       
   183 	 
       
   184 	result := islandParser1 parse: '__ aabb __ cc __'.
       
   185 	self assert: result isPetitFailure not.
       
   186 !
       
   187 
       
   188 testIslandAfterIslandPlus2
       
   189 	
       
   190 	| island2 islandParser2 island1 islandParser1 parser |
       
   191 	
       
   192 	island1 := 'aa' asParser, 'bb' asParser.
       
   193 	islandParser1 := self islandInstance.
       
   194 	islandParser1 island: island1.
       
   195 	
       
   196 	island2 := 'cc' asParser.
       
   197 	islandParser2 := self islandInstance.
       
   198 	islandParser2 island: island2.
       
   199 	
       
   200 	parser := (islandParser1, islandParser2) plus.
       
   201 	 
       
   202 	result := islandParser1 parse: '__ aaxx __ cc __'.
       
   203 	self assert: result isPetitFailure.
       
   204 !
       
   205 
       
   206 testIslandDetection
       
   207 	| island parser |
       
   208 	island := 'class' asParser, self identifier trim, 'endclass' asParser.
       
   209 	parser := self island: island.
       
   210 	
       
   211 	self assert: parser parse: 'class Foo endclass'.
       
   212 	self assert: result size = 3.
       
   213 	self assert: result second second = 'Foo'.
       
   214 
       
   215 	self assert: parser parse: '/*comment*/ class Foo endclass'.
       
   216 	self assert: result size = 3.
       
   217 	self assert: result second second = 'Foo'.
       
   218 
       
   219 	self assert: parser parse: '/*comment class Bar */ class Foo endclass'.
       
   220 	self assert: result size = 3.
       
   221 	self assert: result second second = 'Foo'.
       
   222 
       
   223 	self assert: parser parse: '/*comment class Bar */ class Foo endclass //something more'.
       
   224 	self assert: result size = 3.
       
   225 	self assert: result second second = 'Foo'.
       
   226 
       
   227 	self assert: parser parse: '/*comment class Bar endclass */ class Foo endclass //something more'.
       
   228 	self assert: result size = 3.
       
   229 	self assert: result second second = 'Bar'.
       
   230 !
       
   231 
       
   232 testIslandPlus
       
   233 	
       
   234 	| island  parser |
       
   235 	island := self island: 'X' asParser.
       
   236 	parser := island plus.
       
   237 	
       
   238 	self assert: parser parse: '....X....'.
       
   239 	self assert: result size = 1.
       
   240 
       
   241 	self assert: parser parse: '...X...X...XX'.
       
   242 	self assert: result size = 4.
       
   243 
       
   244 	self assert: parser fail: '.....'.
       
   245 !
       
   246 
       
   247 testIslandPlus2
       
   248 	
       
   249 	| island  parser |
       
   250 	island := self island: ('class' asParser, self identifier trim).
       
   251 	parser := island plus.
       
   252 	
       
   253 	self assert: parser parse: '....class Foo....'.
       
   254 	self assert: result size = 1.
       
   255 	self assert: result first second second = 'Foo'.
       
   256 
       
   257 
       
   258 	self assert: parser parse: '....class . class Foo....'.
       
   259 	self assert: result size = 1.
       
   260 	self assert: result first second second = 'Foo'.
       
   261 
       
   262 	self assert: parser parse: '....class . class Foo class Bar....'.
       
   263 	self assert: result size = 2.
       
   264 	self assert: result first second second = 'Foo'.
       
   265 	self assert: result second second second = 'Bar'.
       
   266 
       
   267 
       
   268 
       
   269 	self assert: parser fail: '.....'.
       
   270 !
       
   271 
       
   272 testIslandSequence
       
   273 	
       
   274 	|  parser   a b c |
       
   275 	"Island sequence will never cross the boundery of 'c'"
       
   276 	a := 'a' asParser.
       
   277 	b := 'b' asParser.
       
   278 	c := 'c' asParser.
       
   279 	
       
   280 	parser := (self island: a), (self island: b), c.
       
   281 	
       
   282 	self assert: parser parse: '..a...b...c'.
       
   283 	self assert: parser fail: '..a..c...b..c'.
       
   284 	self assert: parser fail: '..c..a.....b..c'.
       
   285 !
       
   286 
       
   287 testIslandSequence2
       
   288 	| p a b |
       
   289 	
       
   290 	a := self island: ('a' asParser plus).
       
   291 	a name: 'a island'.
       
   292 	
       
   293 	b := self island: 'b' asParser.
       
   294 	b name: 'b island'.
       
   295 	
       
   296 	p := a optional, (b / self nilIsland).
       
   297 	self assert: p  parse: 'a'.
       
   298 	self assert: result size = 2.
       
   299 	self assert: result first notNil.
       
   300 	self assert: result second size = 3.
       
   301 	self assert: result second second = nil.
       
   302 	
       
   303 	self assert: p parse: '..ab'.
       
   304 	
       
   305 	self assert: result isPetitFailure not.
       
   306 	self assert: result size = 2.
       
   307 	self assert: result first notNil.
       
   308 	self assert: result second size = 3.
       
   309 	self assert: result second second = 'b'.
       
   310 	
       
   311 	self assert: p parse: 'a..b'.
       
   312 	
       
   313 	self assert: result isPetitFailure not.
       
   314 	self assert: result size = 2.
       
   315 	self assert: result first notNil.
       
   316 	self assert: result second size = 3.
       
   317 	self assert: result second second = 'b'.
       
   318 	
       
   319 	self assert: p parse: 'ab...'.
       
   320 	
       
   321 	self assert: result isPetitFailure not.
       
   322 	self assert: result size = 2.
       
   323 	self assert: result first notNil.
       
   324 	self assert: result second size = 3.
       
   325 	self assert: result second second = 'b'.
       
   326 	
       
   327 	self assert: p parse: '...a...b...'.
       
   328 	
       
   329 	self assert: result isPetitFailure not.
       
   330 	self assert: result size = 2.
       
   331 	self assert: result first notNil.
       
   332 	self assert: result second size = 3.
       
   333 	self assert: result second second = 'b'.
       
   334 	
       
   335 	self assert: p parse: '...a...b...'.
       
   336 	
       
   337 	self assert: result isPetitFailure not.
       
   338 	self assert: result size = 2.
       
   339 	self assert: result first notNil.
       
   340 	self assert: result second size = 3.
       
   341 	self assert: result second second = 'b'.
       
   342 	
       
   343 	self assert: p end parse: '...b...'.
       
   344 	
       
   345 	self assert: result isPetitFailure not.
       
   346 	self assert: result size = 2.
       
   347 	self assert: result first isNil.
       
   348 	self assert: result second size = 3.
       
   349 	self assert: result second second = 'b'.
       
   350 !
       
   351 
       
   352 testIslandSequence3
       
   353 	
       
   354 	| parser   body class extends |
       
   355 	class := self island: 'class' asParser trim, self identifier trim.	
       
   356 	extends := self island: 'extends' asParser trim, self identifier trim.
       
   357 	body := self island: self nestedBlock.
       
   358 
       
   359 	parser := (class, extends optional, body) plus.
       
   360 	self assert: parser parse: '
       
   361 	/* lorem ipsum */ 
       
   362 	class Foo { whatever } 
       
   363 	
       
   364 	// something more 
       
   365 	class Bar extends Zorg { blah blah bla } 
       
   366 	// this is the end'.
       
   367 	
       
   368 	self assert: result isPetitFailure not.
       
   369 	self assert: result size = 2. 
       
   370 !
       
   371 
       
   372 testIslandStar
       
   373 	|  p  |
       
   374 	
       
   375 	
       
   376 	p := (self island: 'a' asParser) star, 'b' asParser. 
       
   377 	self assert: p parse: 'b'.
       
   378 	self assert: result size = 2.
       
   379 	self assert: result first size = 0.
       
   380 	
       
   381 	self assert: p parse: 'ab'.
       
   382 	self assert: result size = 2.
       
   383 	self assert: result first size = 1.
       
   384 	
       
   385 	self assert: p parse: 'aab'.
       
   386 	self assert: result size = 2.
       
   387 	self assert: result first size = 2.
       
   388 	
       
   389 	self assert: p parse: '...aab'.
       
   390 	self assert: result size = 2.
       
   391 	self assert: result first size = 2.
       
   392 	
       
   393 	self assert: p parse: '...aa...b'.
       
   394 	self assert: result size = 2.
       
   395 	self assert: result first size = 2.
       
   396 	
       
   397 	self assert: p parse: '...a...a...b'.
       
   398 	self assert: result size = 2.
       
   399 	self assert: result first size = 2.
       
   400 
       
   401 	self assert: p parse: '...a...a...aa...b'.
       
   402 	self assert: result size = 2.
       
   403 	self assert: result first size = 4.
       
   404 	
       
   405 	"Thats the question, if I want this:"
       
   406 	self assert: p fail: '...b'.
       
   407 !
       
   408 
       
   409 testIslandStar2
       
   410 	|  p  |
       
   411 	
       
   412 	
       
   413 	p := (self island: 'a' asParser) star, 'b' asParser optional. 
       
   414 	self assert: p parse: 'aa'.
       
   415 	self assert: result size = 2.
       
   416 	self assert: result first size = 2.
       
   417 	
       
   418 	self assert: p parse: '....aa'.
       
   419 	self assert: result size = 2.
       
   420 	self assert: result first size = 2.
       
   421 	
       
   422 	self assert: p parse: '...a...a...'.
       
   423 	self assert: result size = 2.
       
   424 	self assert: result first size = 2.
       
   425 	
       
   426 	self assert: p parse: '...a...a...b'.
       
   427 	self assert: result size = 2.
       
   428 	self assert: result first size = 2.
       
   429 	self assert: result second = 'b'.
       
   430 !
       
   431 
       
   432 testIslandStar3
       
   433 	|  p  |
       
   434 	
       
   435 	
       
   436 	p := (self island: 'a' asParser) star, (self island: nil asParser). 
       
   437 	
       
   438 	self assert: p parse: '....'.
       
   439 	self assert: result size = 2.
       
   440 	self assert: result first size = 0.
       
   441 	
       
   442 	self assert: p parse: 'aa'.
       
   443 	self assert: result size = 2.
       
   444 	self assert: result first size = 2.
       
   445 	
       
   446 	self assert: p parse: '....aa'.
       
   447 	self assert: result size = 2.
       
   448 	self assert: result first size = 2.
       
   449 	
       
   450 	self assert: p parse: '...a...a...'.
       
   451 	self assert: result size = 2.
       
   452 	self assert: result first size = 2.
       
   453 	
       
   454 	self assert: p parse: '...a...a...b'.
       
   455 	self assert: result size = 2.
       
   456 	self assert: result first size = 2.
       
   457 	self assert: result second second = nil.
       
   458 !
       
   459 
       
   460 testNestedIsland
       
   461 	
       
   462 	|  nestedIsland before after topIsland |
       
   463 	nestedIsland := self island: 'X' asParser.
       
   464 	
       
   465 	before := 'before' asParser.
       
   466 	after := 'after' asParser.
       
   467 	topIsland := self island: (before, nestedIsland, after).
       
   468 	
       
   469 	self assert: nestedIsland parse: 'before...X...ater'.
       
   470 	self assert: topIsland parse: 'beforeXafter'.
       
   471 	
       
   472 	self assert: topIsland parse: '....before..X..after....'.
       
   473 	self assert: result size = 3.
       
   474 	self assert: result second size = 3.
       
   475 	self assert: result second second size = 3.
       
   476 	self assert: result second second second = 'X'.
       
   477 	
       
   478 	self assert: topIsland parse: '....X....before...X....after'.
       
   479 	self assert: topIsland parse: '....before.......after....before..X...after'.
       
   480 
       
   481 	self assert: topIsland fail: '....before.......after...'.	
       
   482 	self assert: topIsland fail: '....before.......after...X'.	
       
   483 	self assert: topIsland fail: '....before.......after...X...after'.		
       
   484 !
       
   485 
       
   486 testNilIsland
       
   487 	
       
   488 	| nilIsland  p |
       
   489 
       
   490 	nilIsland := self nilIsland.
       
   491 	
       
   492 
       
   493 	p := ${ asParser, nilIsland, $} asParser.
       
   494 
       
   495 	self assert: p parse: '{}'.
       
   496 	
       
   497 	self assert: result isCollection.
       
   498 	self assert: result size = 3.
       
   499 	self assert: result first = ${.
       
   500 	self assert: result third = $}.	
       
   501 	
       
   502 
       
   503 	self assert: p parse: '{ }'.
       
   504 	self assert: result isCollection.
       
   505 	self assert: result size = 3.
       
   506 	self assert: result first = ${.
       
   507 	self assert: result third = $}.
       
   508 	
       
   509 
       
   510 	self assert: p parse: '{ ... }'.
       
   511 	self assert: result isCollection.
       
   512 	self assert: result size = 3.
       
   513 	self assert: result first = ${.
       
   514 	self assert: result third = $}.
       
   515 !
       
   516 
       
   517 testOptionalIsland
       
   518 	
       
   519 	| island parser   |
       
   520 	
       
   521 	island := self island: ('a' asParser / 'b' asParser optional).
       
   522 	parser := island, 'c' asParser.
       
   523 	
       
   524 	self assert: parser parse: '....a....b...c'.
       
   525 	self assert: result first second = 'a'.
       
   526 	self assert: result second = 'c'.
       
   527 	
       
   528 	self assert: parser parse: '....d....b...c'.
       
   529 	self assert: result first second = 'b'.
       
   530 	self assert: result second = 'c'.
       
   531 	
       
   532 	self assert: parser parse: '....d....d...c'.
       
   533 	self assert: result first second = nil.
       
   534 	self assert: result second = 'c'.
       
   535 
       
   536 	self assert: parser parse: '...c'.
       
   537 ! !
       
   538 
       
   539 !PPIslandTest methodsFor:'tests - complex'!
       
   540 
       
   541 testClass
       
   542 	| text   file class |
       
   543 	text := '
       
   544 // some comment
       
   545 namespace cde {
       
   546 
       
   547 public class Foo 
       
   548 endclass
       
   549 
       
   550 public class 123 // invalid class
       
   551 public struct {}
       
   552 
       
   553 class bar endclass
       
   554 class Zorg endclass
       
   555 }	
       
   556 	'.
       
   557 	
       
   558 	class := ('public' asParser trim optional, 'class' asParser trim, self identifier,  'endclass' asParser trim) 
       
   559 		==> [:t | t third] .
       
   560 	file := ((self island: class) ==> [:t | t second ]) plus.	
       
   561 	
       
   562 	result := file parse: text.
       
   563 	self assert: result size = 3.
       
   564 	self assert: result first = 'Foo'.
       
   565 	self assert: result second = 'bar'.
       
   566 	self assert: result third = 'Zorg'.
       
   567 !
       
   568 
       
   569 testFile
       
   570 	| text using imports class file |
       
   571 	text := '
       
   572 	
       
   573 using a.b.c;
       
   574 using c.d.e;
       
   575 // some comment
       
   576 namespace cde {
       
   577 
       
   578 public class Foo 
       
   579 endclass
       
   580 
       
   581 public class 123 // invalid class
       
   582 public struct {}
       
   583 
       
   584 class bar endclass
       
   585 }	
       
   586 	'.
       
   587 	
       
   588 	using := 'using' asParser trim, (self identifier, ('.' asParser, self identifier) star) flatten ==> [:t | t second].
       
   589 	
       
   590 	imports := (self island: using) star.
       
   591 	
       
   592 	class := ('public' asParser trim optional, 'class' asParser trim, self identifier,  'endclass' asParser trim) 
       
   593 		==> [:t | t third] .
       
   594 	file := imports, ((self island: class) ==> [:t | t second ]) plus.	
       
   595 	
       
   596 	result := file parse: text.
       
   597 	
       
   598 	self assert: result isPetitFailure not.
       
   599 !
       
   600 
       
   601 testFile2
       
   602 	| text using imports class file |
       
   603 	text := '
       
   604 	
       
   605 using a.b.c;
       
   606 using c.d.e;
       
   607 // some comment
       
   608 namespace cde {
       
   609 
       
   610 class Foo 
       
   611 endclass
       
   612 
       
   613 public class 123 // invalid class
       
   614 public struct {}
       
   615 
       
   616 class bar endclass
       
   617 }	
       
   618 	'.
       
   619 	
       
   620 	using := 'using' asParser trim, (self identifier, ('.' asParser, self identifier) star) flatten ==> [:t | t second].
       
   621 	
       
   622 	imports := (self island: using) star.
       
   623 	
       
   624 	class := ('public' asParser trim optional, 'class' asParser trim, self identifier,  'endclass' asParser trim) 
       
   625 		==> [:t | t third] .
       
   626 	file := imports, ((self island: class) ==> [:t | t second ]) plus.	
       
   627 	
       
   628 	result := file parse: text.
       
   629 	
       
   630 	self assert: result isPetitFailure not.
       
   631 !
       
   632 
       
   633 testImports
       
   634 	| text using imports   |
       
   635 	text := '
       
   636 
       
   637 /** whatever */	
       
   638 using a.b.c;
       
   639 // another comment
       
   640 using c.d.e;
       
   641 // some comment
       
   642 namespace cde {
       
   643 }	
       
   644 	'.
       
   645 	
       
   646 	using := 'using' asParser trim, (self identifier, ('.' asParser, self identifier) star) flatten ==> [:t | t second].
       
   647 	imports := ((self island: using) ==> [:t | t second ]) star.
       
   648 	
       
   649 	result := imports parse: text.
       
   650 	
       
   651 	self assert: result size = 2.
       
   652 	self assert: result first = 'a.b.c'.
       
   653 	self assert: result second = 'c.d.e'.
       
   654 ! !
       
   655 
       
   656 !PPIslandTest methodsFor:'tests - water objects'!
       
   657 
       
   658 multilineCommentParser
       
   659 	^ '/*' asParser, (#any asParser starLazy: '*/' asParser), '*/' asParser.
       
   660 !
       
   661 
       
   662 singleCommentParser
       
   663 	| nl |
       
   664 	nl := #newline asParser.
       
   665 	^ '//' asParser, (#any asParser starLazy: nl), nl.
       
   666 !
       
   667 
       
   668 testMultilineComment
       
   669 	|  parser |
       
   670 	parser := self multilineCommentParser.
       
   671 	
       
   672 	self assert: parser parse: '/* hello there */'.
       
   673 	self assert: parser parse: '/* class Bar endclass */'.
       
   674 !
       
   675 
       
   676 testWaterObjects
       
   677 	| parser |
       
   678 	context := PPContext new.
       
   679 	parser := (self island: ('class' asParser, self identifier trim, 'endclass' asParser ==> #second)) star.
       
   680 
       
   681 	self assert: parser parse: ' /* hello there */ class Foo endclass'.
       
   682 	self assert: result size = 1.
       
   683 	self assert: result first second = 'Foo'.
       
   684 	
       
   685 	context := PPContext new.
       
   686 	self assert: parser parse: ' /* class Bar endclass */ class Foo endclass'.
       
   687 	self assert: result size = 2.
       
   688 	self assert: result first second = 'Bar'.
       
   689 	self assert: result second second = 'Foo'.
       
   690 	
       
   691 	context := PPContext new.
       
   692 	parser := (self island: ('class' asParser, self identifier trim, 'endclass' asParser ==> #second) water: self multilineCommentParser / #any asParser) star.
       
   693 
       
   694 	self assert: parser parse: ' /* class Bar endclass */ class Foo endclass'.
       
   695 	self assert: result size = 1.
       
   696 	self assert: result first second = 'Foo'.
       
   697 !
       
   698 
       
   699 testWaterObjects2
       
   700 	| parser source |
       
   701 	context := PPContext new.
       
   702 
       
   703 	parser := (self island: ('class' asParser, self identifier trim, 'endclass' asParser ==> #second)
       
   704 						 water: self multilineCommentParser / self singleCommentParser / #any asParser) 				star.
       
   705 	
       
   706 	source := ' /* class Bar endclass */ 
       
   707 	class Foo 
       
   708 	endclass
       
   709 	/* 
       
   710 	   class Borg
       
   711 	   endclass
       
   712 	*/
       
   713 	// class Qwark endclass 
       
   714 	class Zorg 
       
   715 	endclass
       
   716 	'.
       
   717 	
       
   718 	self assert: parser parse: source.
       
   719 	self assert: result size = 2.
       
   720 	self assert: result first second = 'Foo'.	
       
   721 	self assert: result second second = 'Zorg'.	
       
   722 ! !
       
   723