Changeset 3287
- Timestamp:
- 01/05/09 08:45:24 (11 months ago)
- Location:
- trunk
- Files:
-
- 16 modified
- 4 moved
-
Library/CompilerLibrary.fsi (modified) (2 diffs)
-
Library/CompilerLibrary.fss (modified) (2 diffs)
-
Library/File.fsi (modified) (3 diffs)
-
Library/File.fss (modified) (6 diffs)
-
Library/FlatString.fsi (moved) (moved from trunk/Library/JavaString.fsi) (2 diffs)
-
Library/FlatString.fss (moved) (moved from trunk/Library/JavaString.fss) (11 diffs)
-
Library/FortressLibrary.fsi (modified) (4 diffs)
-
Library/FortressLibrary.fss (modified) (4 diffs)
-
Library/Reader.fsi (modified) (2 diffs)
-
Library/Reader.fss (modified) (3 diffs)
-
Library/Stream.fsi (modified) (3 diffs)
-
Library/Stream.fss (modified) (3 diffs)
-
Library/String.fss (modified) (29 diffs)
-
Library/Writer.fss (modified) (3 diffs)
-
ProjectFortress/LibraryBuiltin/CompilerBuiltin.fsi (modified) (2 diffs)
-
ProjectFortress/LibraryBuiltin/CompilerBuiltin.fss (modified) (2 diffs)
-
ProjectFortress/src/com/sun/fortress/interpreter/glue/prim/FlatString.java (moved) (moved from trunk/ProjectFortress/src/com/sun/fortress/interpreter/glue/prim/JavaString.java) (20 diffs)
-
ProjectFortress/tests/LongStringTests.fss (modified) (2 diffs)
-
ProjectFortress/tests/StringTests.fss (modified) (2 diffs)
-
Sandbox/FlatStringIsGenerator.fss (moved) (moved from trunk/Sandbox/JavaStringIsGenerator.fss) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Library/CompilerLibrary.fsi
r3242 r3287 1 1 (******************************************************************************* 2 Copyright 200 8Sun Microsystems, Inc.,2 Copyright 2009 Sun Microsystems, Inc., 3 3 4150 Network Circle, Santa Clara, California 95054, U.S.A. 4 4 All rights reserved. … … 18 18 api CompilerLibrary 19 19 20 print(s: JavaString): ()21 println(s: JavaString): ()20 print(s:FlatString): () 21 println(s:FlatString): () 22 22 23 23 trait String -
trunk/Library/CompilerLibrary.fss
r3242 r3287 1 1 (******************************************************************************* 2 Copyright 200 8Sun Microsystems, Inc.,2 Copyright 2009 Sun Microsystems, Inc., 3 3 4150 Network Circle, Santa Clara, California 95054, U.S.A. 4 4 All rights reserved. … … 19 19 export CompilerLibrary 20 20 21 print(s: JavaString): () = builtinPrimitive("com.sun.fortress.interpreter.glue.prim.StringPrim$Print")22 println(s: JavaString): () = builtinPrimitive("com.sun.fortress.interpreter.glue.prim.StringPrim$Println")21 print(s:FlatString): () = builtinPrimitive("com.sun.fortress.interpreter.glue.prim.StringPrim$Print") 22 println(s:FlatString): () = builtinPrimitive("com.sun.fortress.interpreter.glue.prim.StringPrim$Println") 23 23 24 24 trait String -
trunk/Library/File.fsi
r3057 r3287 1 1 (******************************************************************************* 2 Copyright 200 8Sun Microsystems, Inc.,2 Copyright 2009 Sun Microsystems, Inc., 3 3 4150 Network Circle, Santa Clara, California 95054, U.S.A. 4 4 All rights reserved. … … 17 17 18 18 api File 19 import JavaString.JavaString19 import FlatString.FlatString 20 20 import FileSupport.{...} 21 21 … … 103 103 (** A %FileWriteStream% represents a writable stream backed by a file 104 104 named %fileName%. **) 105 105 106 106 FileWriteStream(fileName:String): FileWriteStream 107 108 object FileWriteStream(fileName: JavaString) extends { FileStream }107 108 object FileWriteStream(fileName:FlatString) extends { FileStream } 109 109 getter fileName(): String 110 110 111 (** %write( JavaString)% and %write(Char)% are the primitive mechanisms for writing111 (** %write(FlatString)% and %write(Char)% are the primitive mechanisms for writing 112 112 characters to the end of a %FileWriteStream%. **) 113 write(x: JavaString):()113 write(x:FlatString):() 114 114 write(c:Char):() 115 115 (** %write(Any)% converts its argument to a String using %toString% -
trunk/Library/File.fss
r3179 r3287 1 1 (******************************************************************************* 2 Copyright 200 8Sun Microsystems, Inc.,2 Copyright 2009 Sun Microsystems, Inc., 3 3 4150 Network Circle, Santa Clara, California 95054, U.S.A. 4 4 All rights reserved. … … 17 17 18 18 native component File 19 import JavaString.JavaString19 import FlatString.FlatString 20 20 import FileSupport.{...} 21 21 export File … … 24 24 private package="com.sun.fortress.interpreter.glue.prim" 25 25 26 FileReadStream(filename: String): FileReadStream = FileReadStream(filename.as JavaString)26 FileReadStream(filename: String): FileReadStream = FileReadStream(filename.asFlatString) 27 27 28 object FileReadStream(filename: JavaString)28 object FileReadStream(filename: FlatString) 29 29 extends { ReadStream, FileStream } 30 30 getter fileName():String = … … 68 68 end 69 69 70 FileWriteStream(fileName:String) = FileWriteStream(fileName.as JavaString)70 FileWriteStream(fileName:String) = FileWriteStream(fileName.asFlatString) 71 71 72 object FileWriteStream(fileName: JavaString) extends { FileStream }72 object FileWriteStream(fileName:FlatString) extends { FileStream } 73 73 getter fileName(): String = 74 74 builtinPrimitive( … … 77 77 builtinPrimitive( 78 78 "com.sun.fortress.interpreter.glue.prim.FileWriteStream$toString") 79 write(s: JavaString):() =79 write(s:FlatString):() = 80 80 builtinPrimitive( 81 81 "com.sun.fortress.interpreter.glue.prim.FileWriteStream$write") … … 88 88 write((BIG ||[e <- x] 89 89 typecase e of 90 JavaString => e91 String => e.as JavaString92 else => ("" e).as JavaString90 FlatString => e 91 String => e.asFlatString 92 else => ("" e).asFlatString 93 93 end) r) 94 94 writes(x:Generator[\Any\]):() = writes(x,"") -
trunk/Library/FlatString.fsi
r3196 r3287 1 1 (******************************************************************************* 2 Copyright 200 8Sun Microsystems, Inc.,2 Copyright 2009 Sun Microsystems, Inc., 3 3 4150 Network Circle, Santa Clara, California 95054, U.S.A. 4 4 All rights reserved. … … 16 16 ******************************************************************************) 17 17 18 api JavaString18 api FlatString 19 19 20 lineSeparator: String 21 22 object JavaString extends { String }23 opr ||(self, b: JavaString): String20 lineSeparator: String 21 22 object FlatString extends { String } 23 opr ||(self, b:FlatString): String 24 24 opr ||(self, b:String):String 25 opr ||(self, b:Char): String 26 opr ||(a: JavaString, self): String27 javaConcat(self, b:JavaString):String28 javaConcat(self, b:Char):String25 opr ||(self, b:Char): String 26 opr ||(a:FlatString, self): String 27 flatConcat(self, b:FlatString):String 28 flatConcat(self, b:Char):String 29 29 end 30 30 31 31 end -
trunk/Library/FlatString.fss
r3242 r3287 1 1 (******************************************************************************* 2 Copyright 200 8Sun Microsystems, Inc.,2 Copyright 2009 Sun Microsystems, Inc., 3 3 4150 Network Circle, Santa Clara, California 95054, U.S.A. 4 4 All rights reserved. … … 16 16 ******************************************************************************) 17 17 18 native component JavaString18 native component FlatString 19 19 20 20 import String.{maxLeafSize, concatAndBalanceIfNecessary, CatString, spaces} 21 21 import Stream.{...} 22 22 23 export JavaString23 export FlatString 24 24 25 25 … … 33 33 34 34 private LineSeparator(): String =do 35 JavaString; (* This initializes the constructor for JavaString35 FlatString; (* This initializes the constructor for FlatString 36 36 before its type is used (in the next line). *) 37 37 natLineSeparator() 38 38 end 39 39 40 object JavaString extends { String, DelegatedIndexed⟦Char, ZZ32⟧ }40 object FlatString extends { String, DelegatedIndexed⟦Char, ZZ32⟧ } 41 41 getter size() : ZZ32 = 42 builtinPrimitive("com.sun.fortress.interpreter.glue.prim. JavaString$Size")42 builtinPrimitive("com.sun.fortress.interpreter.glue.prim.FlatString$Size") 43 43 getter asExprString() : String = 44 builtinPrimitive("com.sun.fortress.interpreter.glue.prim. JavaString$ToString")45 getter as JavaString(): String = self44 builtinPrimitive("com.sun.fortress.interpreter.glue.prim.FlatString$ToString") 45 getter asFlatString(): String = self 46 46 getter asStriing(): String = self 47 47 getter asDebugString(): String = asDebugStringIndented(0) … … 57 57 58 58 opr |self| : ZZ32 = 59 builtinPrimitive("com.sun.fortress.interpreter.glue.prim. JavaString$Size")59 builtinPrimitive("com.sun.fortress.interpreter.glue.prim.FlatString$Size") 60 60 61 61 uncheckedSubstring(r1: Range⟦ZZ32⟧) : String = do 62 62 (* We could build a subString node here, but not until everything is working, 63 63 because that will introduce 64 SubString objects into code that may still expect JavaStrings.65 As written, this method always answers a JavaString.66 In any case, the JavaString object supports substring without copying*)64 SubString objects into code that may still expect FlatStrings. 65 As written, this method always answers a FlatString. 66 In any case, the FlatString object supports substring without copying*) 67 67 assert((r1 ∩ self.bounds).isEmpty, r1.isEmpty, 68 68 "Empty substring of non-empty string") … … 72 72 end 73 73 74 opr =(self, other: JavaString): Boolean =75 builtinPrimitive("com.sun.fortress.interpreter.glue.prim. JavaString$Eq")76 opr <(self, other: JavaString): Boolean = self.cmp(other) < 077 opr <=(self, other: JavaString): Boolean = self.cmp(other) ≤ 078 opr >(self, other: JavaString): Boolean = self.cmp(other) > 079 opr >=(self, other: JavaString): Boolean = self.cmp(other) ≥ 080 opr CMP(self, other: JavaString): TotalComparison = self.cmp(other) CMP 074 opr =(self, other: FlatString): Boolean = 75 builtinPrimitive("com.sun.fortress.interpreter.glue.prim.FlatString$Eq") 76 opr <(self, other: FlatString): Boolean = self.cmp(other) < 0 77 opr <=(self, other: FlatString): Boolean = self.cmp(other) ≤ 0 78 opr >(self, other: FlatString): Boolean = self.cmp(other) > 0 79 opr >=(self, other: FlatString): Boolean = self.cmp(other) ≥ 0 80 opr CMP(self, other: FlatString): TotalComparison = self.cmp(other) CMP 0 81 81 opr CMP(self, other:String):TotalComparison = INVERSE (other CMP self) 82 opr CASE_INSENSITIVE_CMP(self, other: JavaString): TotalComparison =82 opr CASE_INSENSITIVE_CMP(self, other:FlatString): TotalComparison = 83 83 self.cicmp(other) CMP 0 84 84 opr CASE_INSENSITIVE_CMP(self, other:String): TotalComparison = INVERSE (other CASE_INSENSITIVE_CMP self) … … 86 86 (** get skips bounds checking. **) 87 87 get(i:ZZ32): Char = 88 builtinPrimitive("com.sun.fortress.interpreter.glue.prim. JavaString$Index")89 cmp(other: JavaString): ZZ32 =90 builtinPrimitive("com.sun.fortress.interpreter.glue.prim. JavaString$Cmp")91 cicmp(other: JavaString): ZZ32 =92 builtinPrimitive("com.sun.fortress.interpreter.glue.prim. JavaString$CICmp")88 builtinPrimitive("com.sun.fortress.interpreter.glue.prim.FlatString$Index") 89 cmp(other:FlatString): ZZ32 = 90 builtinPrimitive("com.sun.fortress.interpreter.glue.prim.FlatString$Cmp") 91 cicmp(other:FlatString): ZZ32 = 92 builtinPrimitive("com.sun.fortress.interpreter.glue.prim.FlatString$CICmp") 93 93 javaSubstr(lo:ZZ32,hi:ZZ32): String = 94 builtinPrimitive("com.sun.fortress.interpreter.glue.prim. JavaString$Substr")94 builtinPrimitive("com.sun.fortress.interpreter.glue.prim.FlatString$Substr") 95 95 javaIndexOf(c:Char): ZZ32 = 96 builtinPrimitive("com.sun.fortress.interpreter.glue.prim. JavaString$IndexOf")97 javaConcat(self, b:JavaString):String =98 builtinPrimitive("com.sun.fortress.interpreter.glue.prim. JavaString$Concat")99 javaConcat(self, b:Char):String =100 builtinPrimitive("com.sun.fortress.interpreter.glue.prim. JavaString$Concat")96 builtinPrimitive("com.sun.fortress.interpreter.glue.prim.FlatString$IndexOf") 97 flatConcat(self, b:FlatString):String = 98 builtinPrimitive("com.sun.fortress.interpreter.glue.prim.FlatString$Concat") 99 flatConcat(self, b:Char):String = 100 builtinPrimitive("com.sun.fortress.interpreter.glue.prim.FlatString$Concat") 101 101 102 102 indexOf(c:Char): Maybe⟦ZZ32⟧ = do … … 118 118 (** The operator %||% with at least one String argument converts to string and 119 119 concatenates **) 120 opr ||(self, b: JavaString): String = do120 opr ||(self, b:FlatString): String = do 121 121 if b.isEmpty then self 122 122 elif self.size + b.size > maxLeafSize then … … 124 124 CatString(self, b) 125 125 else 126 javaConcat(self, b)126 flatConcat(self, b) 127 127 end 128 128 end … … 134 134 concatAndBalanceIfNecessary(self, b) 135 135 else 136 javaConcat(self, b.asJavaString)136 flatConcat(self, b.asFlatString) 137 137 end 138 138 end … … 142 142 concatAndBalanceIfNecessary(self, b.asString) 143 143 else 144 javaConcat(self, b)144 flatConcat(self, b) 145 145 end 146 146 … … 150 150 writeOn(stream: WriteStream): () = stream.write(self) 151 151 152 end JavaString152 end FlatString 153 153 154 154 end -
trunk/Library/FortressLibrary.fsi
r3201 r3287 1 1 (******************************************************************************* 2 Copyright 200 8Sun Microsystems, Inc.,2 Copyright 2009 Sun Microsystems, Inc., 3 3 4150 Network Circle, Santa Clara, California 95054, U.S.A. 4 4 All rights reserved. … … 19 19 20 20 import Stream.WriteStream 21 import JavaString.JavaString21 import FlatString.FlatString 22 22 import String.StringStats 23 23 … … 2121 2121 getter indices() : CompactFullRange[\ZZ32\] 2122 2122 getter depth() : ZZ32 2123 getter as JavaString(): String2123 getter asFlatString(): String 2124 2124 getter isBalanced(): Boolean 2125 2125 … … 2224 2224 random(a:Number):RR64 2225 2225 2226 match(regex: JavaString,some:JavaString):Boolean2226 match(regex:FlatString,some:FlatString):Boolean 2227 2227 2228 2228 (** %char% converts an integer unicode code point into the -
trunk/Library/FortressLibrary.fss
r3237 r3287 1 1 (******************************************************************************* 2 Copyright 200 8Sun Microsystems, Inc.,2 Copyright 2009 Sun Microsystems, Inc., 3 3 4150 Network Circle, Santa Clara, California 95054, U.S.A. 4 4 All rights reserved. … … 19 19 import NativeArray.{...} 20 20 import NatReflect.{...} 21 import JavaString.{...}21 import FlatString.{...} 22 22 import RangeInternals.{...} 23 23 import List.{AnyList} … … 3633 3633 getter generator() : Generator[\Char\] = 3634 3634 self.indices.map[\Char\](fn (i:ZZ32):Char => self[i]) 3635 getter as JavaString(): String3635 getter asFlatString(): String 3636 3636 3637 3637 opr |self| : ZZ32 = self.size … … 3812 3812 strToInt(s: String): ZZ32 = strToInt(s,10) 3813 3813 3814 match(regex: JavaString,some:JavaString):Boolean = builtinPrimitive("com.sun.fortress.interpreter.glue.prim.StringPrim$Match")3814 match(regex:FlatString,some:FlatString):Boolean = builtinPrimitive("com.sun.fortress.interpreter.glue.prim.StringPrim$Match") 3815 3815 3816 3816 (** postfix %//% appends a single line separator. The postfix version -
trunk/Library/Reader.fsi
r3196 r3287 1 1 (******************************************************************************* 2 Copyright 200 8Sun Microsystems, Inc.,2 Copyright 2009 Sun Microsystems, Inc., 3 3 4150 Network Circle, Santa Clara, California 95054, U.S.A. 4 4 All rights reserved. … … 17 17 18 18 api Reader 19 import JavaString.JavaString19 import FlatString.FlatString 20 20 import Stream.{...} 21 21 stdIn: Reader -
trunk/Library/Reader.fss
r3196 r3287 1 1 (******************************************************************************* 2 Copyright 200 8Sun Microsystems, Inc.,2 Copyright 2009 Sun Microsystems, Inc., 3 3 4150 Network Circle, Santa Clara, California 95054, U.S.A. 4 4 All rights reserved. … … 17 17 18 18 native component Reader 19 import JavaString.JavaString19 import FlatString.FlatString 20 20 import Stream.{...} 21 21 export Reader … … 24 24 package="com.sun.fortress.interpreter.glue.prim" 25 25 26 stdIn: Reader = InReader()27 28 private InReader(): Reader = builtinPrimitive(29 "com.sun.fortress.interpreter.glue.prim.Reader$inputReader")30 31 object Reader(fileName: String) extends { ReadStream }32 getter asString(): String = "Reader on " self.fileName.asExprString33 getter fileName(): String =34 builtinPrimitive(35 "com.sun.fortress.interpreter.glue.prim.Reader$fileName")36 37 getter eof():Boolean =38 builtinPrimitive(39 "com.sun.fortress.interpreter.glue.prim.Reader$eof")40 41 getter isReady():Boolean =42 builtinPrimitive(43 "com.sun.fortress.interpreter.glue.prim.Reader$ready")44 45 whenUnconsumed():() =46 builtinPrimitive(47 "com.sun.fortress.interpreter.glue.prim.Reader$whenUnconsumed")48 consume():() =49 builtinPrimitive(50 "com.sun.fortress.interpreter.glue.prim.Reader$consume")51 52 uncheckedReadLine():String =53 builtinPrimitive(54 "com.sun.fortress.interpreter.glue.prim.Reader$readLine")55 56 uncheckedReadChar():ZZ32 =57 builtinPrimitive(58 "com.sun.fortress.interpreter.glue.prim.Reader$readChar")59 60 uncheckedRead(k:ZZ32):String =61 builtinPrimitive(62 "com.sun.fortress.interpreter.glue.prim.Reader$readk")63 64 close():() =65 builtinPrimitive(66 "com.sun.fortress.interpreter.glue.prim.Reader$close")67 end Reader68 26 stdIn: Reader = InReader() 27 28 private InReader(): Reader = builtinPrimitive( 29 "com.sun.fortress.interpreter.glue.prim.Reader$inputReader") 30 31 object Reader(fileName: String) extends { ReadStream } 32 getter asString(): String = "Reader on " self.fileName.asExprString 33 getter fileName(): String = 34 builtinPrimitive( 35 "com.sun.fortress.interpreter.glue.prim.Reader$fileName") 36 37 getter eof():Boolean = 38 builtinPrimitive( 39 "com.sun.fortress.interpreter.glue.prim.Reader$eof") 40 41 getter isReady():Boolean = 42 builtinPrimitive( 43 "com.sun.fortress.interpreter.glue.prim.Reader$ready") 44 45 whenUnconsumed():() = 46 builtinPrimitive( 47 "com.sun.fortress.interpreter.glue.prim.Reader$whenUnconsumed") 48 consume():() = 49 builtinPrimitive( 50 "com.sun.fortress.interpreter.glue.prim.Reader$consume") 51 52 uncheckedReadLine():String = 53 builtinPrimitive( 54 "com.sun.fortress.interpreter.glue.prim.Reader$readLine") 55 56 uncheckedReadChar():ZZ32 = 57 builtinPrimitive( 58 "com.sun.fortress.interpreter.glue.prim.Reader$readChar") 59 60 uncheckedRead(k:ZZ32):String = 61 builtinPrimitive( 62 "com.sun.fortress.interpreter.glue.prim.Reader$readk") 63 64 close():() = 65 builtinPrimitive( 66 "com.sun.fortress.interpreter.glue.prim.Reader$close") 67 end Reader 68 69 69 end -
trunk/Library/Stream.fsi
r3235 r3287 1 1 (******************************************************************************* 2 Copyright 200 8Sun Microsystems, Inc.,2 Copyright 2009 Sun Microsystems, Inc., 3 3 4150 Network Circle, Santa Clara, California 95054, U.S.A. 4 4 All rights reserved. … … 17 17 18 18 api Stream 19 import JavaString.JavaString19 import FlatString.FlatString 20 20 21 21 (*********************************************************** … … 38 38 trait WriteStream extends { Closeable } 39 39 40 (** %write( JavaString)% and %write(Char)% are the primitive mechanisms40 (** %write(FlatString)% and %write(Char)% are the primitive mechanisms 41 41 for writing characters to the end of a %WriteStream%. 42 write( JavaString) need not be part of this api, since it is covered by42 write(FlatString) need not be part of this api, since it is covered by 43 43 write(String) **) 44 44 -
trunk/Library/Stream.fss
r3235 r3287 1 1 (******************************************************************************* 2 Copyright 200 8Sun Microsystems, Inc.,2 Copyright 2009 Sun Microsystems, Inc., 3 3 4150 Network Circle, Santa Clara, California 95054, U.S.A. 4 4 All rights reserved. … … 17 17 18 18 component Stream 19 import JavaString.JavaString19 import FlatString.FlatString 20 20 export Stream 21 21 … … 39 39 trait WriteStream extends { Closeable } 40 40 41 (** %write( JavaString)% and %write(Char)% are the primitive mechanisms41 (** %write(FlatString)% and %write(Char)% are the primitive mechanisms 42 42 for writing characters to a %WriteStream%. **) 43 43 -
trunk/Library/String.fss
r3196 r3287 1 1 (******************************************************************************* 2 Copyright 200 8Sun Microsystems, Inc.,2 Copyright 2009 Sun Microsystems, Inc., 3 3 4150 Network Circle, Santa Clara, California 95054, U.S.A. 4 4 All rights reserved. … … 18 18 component String 19 19 import List.{...} 20 import JavaString.{...}20 import FlatString.{...} 21 21 import Stream.{...} 22 22 export String 23 23 24 (* fib is an array of Fibonacci numbers. We start with 24 (* fib is an array of Fibonacci numbers. We start with 25 25 fib[0] = 0 so that the empty string does not have to be a special case. *) 26 26 fib = do … … 42 42 opr || (self, _:EmptyString): String = self 43 43 opr || (self, other:Char) = concatAndBalanceIfNecessary(self, other.asString) 44 44 45 45 end Concatenable 46 46 … … 50 50 getter isExtremelyUnbalanced() = self.depth > 30 AND: (¬ self.isBalanced) 51 51 end Balanceable 52 52 53 53 (* 54 54 ==== CatString ==== … … 59 59 concatAndBalanceIfNecessary(s1: String, s2: String) = do 60 60 result = CatString(s1, s2) 61 if result.isExtremelyUnbalanced 61 if result.isExtremelyUnbalanced 62 62 then result.balanced() 63 63 else result 64 64 end 65 65 end 66 67 concatAndBalanceIfNecessary(s1: CatString, s2: JavaString) = do68 (* This handles the case where s1.right is a short JavaString *)66 67 concatAndBalanceIfNecessary(s1: CatString, s2: FlatString) = do 68 (* This handles the case where s1.right is a short FlatString *) 69 69 typecase r = s1.right of 70 JavaString ⇒ if |r| + |s2| ≤ maxLeafSize then71 s1.left || javaConcat(r, s2)70 FlatString ⇒ if |r| + |s2| ≤ maxLeafSize then 71 s1.left || flatConcat(r, s2) 72 72 else 73 73 concatAndBalanceIfNecessary(s1 asif String, s2) … … 78 78 79 79 (* Object *) 80 80 81 81 object CatString(left: String, right:String) extends {Concatenable, Balanceable} 82 82 size = left.size + right.size … … 86 86 getter generator() = ConcatGenerator(left.generator, right.generator) 87 87 (* if this were to be used heavily, we should collect the result in a StringBuffer *) 88 getter as JavaString() = javaConcat(left.asJavaString, right.asJavaString)89 getter asExprString() = left.asExprString.allButLast() || right.asExprString.allButFirst 88 getter asFlatString() = flatConcat(left.asFlatString, right.asFlatString) 89 getter asExprString() = left.asExprString.allButLast() || right.asExprString.allButFirst 90 90 getter asDebugString(): String = asDebugStringIndented(0) 91 91 92 92 generate⟦R⟧(r: Reduction⟦R⟧, body: Char→R): R = 93 93 r.join(left.generate(r, body), right.generate(r, body)) … … 95 95 opr ∈ (c:Char, self): Boolean = (c IN left) OR (c IN right) 96 96 97 opr CMP(self, other: String) 98 (*) ensures {outcome = (self.as JavaString CMP other.asJavaString)}97 opr CMP(self, other: String) 98 (*) ensures {outcome = (self.asFlatString CMP other.asFlatString)} 99 99 = do 100 100 result = … … 105 105 (left CMP other[0#|left|]) LEXICO: (right CMP other[(|left|):]) LEXICO: (|self| CMP |other|) 106 106 end 107 if result ≠ (self.as JavaString CMP other.asJavaString) then107 if result ≠ (self.asFlatString CMP other.asFlatString) then 108 108 errorPrintln "Callee Failure, self = " self.asDebugString ", CMP other = " other.asDebugString 109 109 errorPrintln "result = " result … … 112 112 end 113 113 114 opr CASE_INSENSITIVE_CMP(self, other:String): TotalComparison 115 (*) ensures {outcome = (self.as JavaString CASE_INSENSITIVE_CMP other.asJavaString)}114 opr CASE_INSENSITIVE_CMP(self, other:String): TotalComparison 115 (*) ensures {outcome = (self.asFlatString CASE_INSENSITIVE_CMP other.asFlatString)} 116 116 = 117 117 if |left| ≥ |other| … … 132 132 end 133 133 134 asDebugStringIndented(indent: ZZ32): String = 134 asDebugStringIndented(indent: ZZ32): String = 135 135 (spaces(indent) || self.balanceIndicator() || "C" || self.size "/" self.depth || ":") // 136 136 left.asDebugStringIndented(indent+8) // 137 137 right.asDebugStringIndented(indent+8) 138 138 139 balanceIndicator() = 139 balanceIndicator() = 140 140 if self.isBalanced then "B" elif self.isAlmostBalanced then "b" else "u" end 141 141 142 142 uncheckedSubstring(r0: Range⟦ZZ32⟧) = label method 143 (* printlnWithThread ("CatString.uncheckedSubstring " self "[" r0 "]").as JavaString *)143 (* printlnWithThread ("CatString.uncheckedSubstring " self "[" r0 "]").asFlatString *) 144 144 if r0.isEmpty then exit method with EmptyString end 145 145 if r0 = self.bounds then exit method with self end … … 162 162 splitWithOffsets(): Generator⟦(ZZ32, String)⟧ = ⟨⟦(ZZ32, String)⟧ (0, left), (|left|, right) ⟩ 163 163 split(): Generator⟦String⟧ = ⟨⟦String⟧ piece | (_, piece) ← self.splitWithOffsets() ⟩ 164 165 balanced() 166 (*) ensures {outcome = self ∧ outcome.isAlmostBalanced} 164 165 balanced() 166 (*) ensures {outcome = self ∧ outcome.isAlmostBalanced} 167 167 = 168 168 label method … … 182 182 |sequence[i]| = 0 ∨ fib[i] ≤ |sequence[i]| < fib[i+1] } *) 183 183 184 getter contents() 185 (*) ensures { |outcome| = cumulativeSize } 184 getter contents() 185 (*) ensures { |outcome| = cumulativeSize } 186 186 = do 187 187 (* We could do this all with a BIG || of a sequential generator. … … 233 233 end 234 234 235 add(s: JavaString) =235 add(s: FlatString) = 236 236 do 237 237 self.addWholeSubtree(s) … … 279 279 getter depth() = 0 280 280 getter isEmpty() = true 281 getter as JavaString() = ""281 getter asFlatString() = "" 282 282 getter asExprString() = "\"\"" 283 283 getter asDebugString(): String = asDebugStringIndented(0) 284 284 285 285 asDebugStringIndented(indent: ZZ32) = spaces(indent) "E" |self| "/" self.depth 286 286 287 287 generate⟦R⟧(r: Reduction⟦R⟧, body: Char→R): R = r.empty() 288 288 289 289 opr ∈ (c:Char, self): Boolean = false 290 290 291 291 rangeContains(r: Range⟦ZZ32⟧, c: Char) = false 292 292 … … 309 309 end 310 310 311 uncheckedSubstring(r0: Range⟦ZZ32⟧) 311 uncheckedSubstring(r0: Range⟦ZZ32⟧) 312 312 (*) requires { r0.isEmpty } 313 313 = … … 325 325 326 326 end EmptyString 327 327 328 328 test stringifyChars() = do 329 329 f:Char = 'f' … … 346 346 getter depth() = baseString.depth (* We pretend that substring nodes don't add depth *) 347 347 getter isEmpty() = false (* Because we take care never to construct an empty SubString *) 348 getter as JavaString() = baseString.asJavaString.uncheckedSubstring(range)349 getter asExprString() = self.as JavaString.asExprString348 getter asFlatString() = baseString.asFlatString.uncheckedSubstring(range) 349 getter asExprString() = self.asFlatString.asExprString 350 350 getter asDebugString(): String = asDebugStringIndented(0) 351 351 getter isBalanced() = baseString.isBalanced 352 353 (* this is a placeholder, until I write the better code using split, or 352 353 (* this is a placeholder, until I write the better code using split, or 354 354 eliminate SubString entirely *) 355 getter generator() : Generator⟦Char⟧ = 355 getter generator() : Generator⟦Char⟧ = 356 356 self.indices.map⟦Char⟧(fn (i:ZZ32):Char => self.get(i)) 357 358 asDebugStringIndented(indent: ZZ32) : String = 357 358 asDebugStringIndented(indent: ZZ32) : String = 359 359 (spaces(indent) || "S" |self| "= [" range.asExprString "]") // 360 360 baseString.asDebugStringIndented(indent + 8) 361 361 362 362 opr |self| : ZZ32 = self.size 363 363 … … 367 367 end 368 368 369 opr CMP(self, other: String) 370 (*) ensures { outcome = (self.as JavaString CMP other.asJavaString) }369 opr CMP(self, other: String) 370 (*) ensures { outcome = (self.asFlatString CMP other.asFlatString) } 371 371 = do 372 372 pieces = baseString.splitWithOffsets() … … 374 374 BIG LEXICO [(start, str) ← pieces] (do 375 375 baseSubrange = (start#|str|) ∩ range 376 baseString.uncheckedSubstring(baseSubrange) CMP 376 baseString.uncheckedSubstring(baseSubrange) CMP 377 377 other.uncheckedSubstring((baseSubrange≪range.lower) ∩ other.indices) 378 378 end) … … 391 391 end 392 392 393 opr CASE_INSENSITIVE_CMP(self, other: String) 394 (*) ensures { outcome = (self.as JavaString CASE_INSENSITIVE_CMP other.asJavaString) }393 opr CASE_INSENSITIVE_CMP(self, other: String) 394 (*) ensures { outcome = (self.asFlatString CASE_INSENSITIVE_CMP other.asFlatString) } 395 395 = do 396 396 pieces = baseString.splitWithOffsets() … … 438 438 "SubString ", baseString, range, " has range greater than that of baseString ", baseString.bounds ) 439 439 typecase s = baseString of 440 CatString ⇒ do 441 deny((s.left.indices ∩ range).isEmpty, 440 CatString ⇒ do 441 deny((s.left.indices ∩ range).isEmpty, 442 442 "SubString of CatString not pushed right") 443 deny(((s.right.indices ≫ s.left.size) ∩ range).isEmpty, 443 deny(((s.right.indices ≫ s.left.size) ∩ range).isEmpty, 444 444 "SubString of CatString not pushed left") 445 445 end … … 466 466 end 467 467 end 468 468 469 469 split(): Generator⟦String⟧ =self.splitWithOffsets().map(fn (_, str) ⇒str) 470 470 … … 475 475 476 476 uncheckedSubstring(r0: Range⟦ZZ32⟧) = do 477 assert((r0≫range.lower) ≤ range, true, "asking for substring [", r0, "] of S", self.size, " = ", self.as JavaString)477 assert((r0≫range.lower) ≤ range, true, "asking for substring [", r0, "] of S", self.size, " = ", self.asFlatString) 478 478 if r0.isEmpty then EmptyString 479 479 elif r0 = self.bounds then self … … 504 504 var ssize: ZZ32 := 0 505 505 var sdepth: ZZ32 := 0 506 506 507 507 getter asString(): String =do 508 a = ("size = " ssize "; depth = " sdepth "; maxFlat = " maxFlat) 508 a = ("size = " ssize "; depth = " sdepth "; maxFlat = " maxFlat) 509 509 b = ("; minFlat = "minFlat "; avFlat = " self.avFlat) 510 510 c = ("; numFlat = " numFlat) 511 511 a || b || c 512 512 end 513 513 514 514 getter avFlat(): RR32 = ssize / (numFlat asif Number) 515 515 … … 521 521 end 522 522 523 collectStatsFor(s: JavaString) = do523 collectStatsFor(s: FlatString) = do 524 524 if ssize = 0 then ssize := |s| end 525 525 if sdepth = 0 then sdepth := s.depth end … … 534 534 self.collectStatsFor(s.baseString) 535 535 end 536 536 537 537 collectStatsFor(s: EmptyString) = do 538 538 minFlat := 0 … … 541 541 end StringStats 542 542 543 spaces(nn: ZZ32): String 544 (*) ensures { |outcome| = nn} 543 spaces(nn: ZZ32): String 544 (*) ensures { |outcome| = nn} 545 545 = do 546 546 spaceString = " " … … 553 553 else 554 554 result := result || spaceString 555 remainder := remainder - |spaceString| 555 remainder := remainder - |spaceString| 556 556 end 557 557 end (* do *) 558 558 result 559 559 end 560 560 561 561 var maxLeafSize: ZZ32 := 32 562 562 563 563 newline: String = lineSeparator 564 564 doubleNewline: String = newline || newline -
trunk/Library/Writer.fss
r3204 r3287 1 1 (******************************************************************************* 2 Copyright 200 8Sun Microsystems, Inc.,2 Copyright 2009 Sun Microsystems, Inc., 3 3 4150 Network Circle, Santa Clara, California 95054, U.S.A. 4 4 All rights reserved. … … 17 17 18 18 native component Writer 19 import JavaString.JavaString19 import FlatString.FlatString 20 20 import Stream.{...} 21 21 export Writer … … 24 24 private package="com.sun.fortress.interpreter.glue.prim" 25 25 26 stdOut: Writer = OutWriter()27 stdErr: Writer = ErrWriter()26 stdOut: Writer = OutWriter() 27 stdErr: Writer = ErrWriter() 28 28 29 private OutWriter(): Writer = builtinPrimitive(30 "com.sun.fortress.interpreter.glue.prim.Writer$outputWriter")31 private ErrWriter(): Writer = builtinPrimitive(32 "com.sun.fortress.interpreter.glue.prim.Writer$errorWriter")29 private OutWriter(): Writer = builtinPrimitive( 30 "com.sun.fortress.interpreter.glue.prim.Writer$outputWriter") 31 private ErrWriter(): Writer = builtinPrimitive( 32 "com.sun.fortress.interpreter.glue.prim.Writer$errorWriter") 33 33 34 object Writer(fileName: String) extends { WriteStream }35 getter asString(): String = "Writer on " self.fileName.asExprString36 getter fileName(): String =37 builtinPrimitive(38 "com.sun.fortress.interpreter.glue.prim.Writer$fileName")39 write(s:JavaString):() =40 builtinPrimitive(41 "com.sun.fortress.interpreter.glue.prim.Writer$write")42 write(c:Char):() =43 builtinPrimitive(44 "com.sun.fortress.interpreter.glue.prim.Writer$write")45 flush():() =46 builtinPrimitive(47 "com.sun.fortress.interpreter.glue.prim.Writer$flush")48 close():() =49 builtinPrimitive(50 "com.sun.fortress.interpreter.glue.prim.Writer$close")51 write(s: String): () = do52 buff = BufferedWriter(self, |s|)53 s.writeOn(buff)54 buff.flush()55 end56 end Writer34 object Writer(fileName: String) extends { WriteStream } 35 getter asString(): String = "Writer on " self.fileName.asExprString 36 getter fileName(): String = 37 builtinPrimitive( 38 "com.sun.fortress.interpreter.glue.prim.Writer$fileName") 39 write(s:FlatString):() = 40 builtinPrimitive( 41 "com.sun.fortress.interpreter.glue.prim.Writer$write") 42 write(c:Char):() = 43 builtinPrimitive( 44 "com.sun.fortress.interpreter.glue.prim.Writer$write") 45 flush():() = 46 builtinPrimitive( 47 "com.sun.fortress.interpreter.glue.prim.Writer$flush") 48 close():() = 49 builtinPrimitive( 50 "com.sun.fortress.interpreter.glue.prim.Writer$close") 51 write(s: String): () = do 52 buff = BufferedWriter(self, |s|) 53 s.writeOn(buff) 54 buff.flush() 55 end 56 end Writer 57 57 58 object BufferedWriter(under: WriteStream, size: ZZ32) extends { WriteStream }59 getter asString(): String = "BufferedWriter on " under.asString60 write(s: String): () = s.writeOn(self)61 write(s: JavaString):() =62 builtinPrimitive(63 "com.sun.fortress.interpreter.glue.prim.BufferedWriter$write")64 write(c: Char):() =65 builtinPrimitive(66 "com.sun.fortress.interpreter.glue.prim.BufferedWriter$write")67 flush():() =68 builtinPrimitive(69 "com.sun.fortress.interpreter.glue.prim.BufferedWriter$flush")70 close():() =71 builtinPrimitive(72 "com.sun.fortress.interpreter.glue.prim.BufferedWriter$close")73 end BufferedWriter58 object BufferedWriter(under: WriteStream, size: ZZ32) extends { WriteStream } 59 getter asString(): String = "BufferedWriter on " under.asString 60 write(s: String): () = s.writeOn(self) 61 write(s: FlatString):() = 62 builtinPrimitive( 63 "com.sun.fortress.interpreter.glue.prim.BufferedWriter$write") 64 write(c: Char):() = 65 builtinPrimitive( 66 "com.sun.fortress.interpreter.glue.prim.BufferedWriter$write") 67 flush():() = 68 builtinPrimitive( 69 "com.sun.fortress.interpreter.glue.prim.BufferedWriter$flush") 70 close():() = 71 builtinPrimitive( 72 "com.sun.fortress.interpreter.glue.prim.BufferedWriter$close") 73 end BufferedWriter 74 74 75 75 end -
trunk/ProjectFortress/LibraryBuiltin/CompilerBuiltin.fsi
r3242 r3287 1 1 (******************************************************************************* 2 Copyright 200 8Sun Microsystems, Inc.,2 Copyright 2009 Sun Microsystems, Inc., 3 3 4150 Network Circle, Santa Clara, California 95054, U.S.A. 4 4 All rights reserved. … … 39 39 end Object 40 40 41 object JavaString42 end JavaString41 object FlatString 42 end FlatString 43 43 44 44 end -
trunk/ProjectFortress/LibraryBuiltin/CompilerBuiltin.fss
r3242 r3287 1 1 (******************************************************************************* 2 Copyright 200 8Sun Microsystems, Inc.,2 Copyright 2009 Sun Microsystems, Inc., 3 3 4150 Network Circle, Santa Clara, California 95054, U.S.A. 4 4 All rights reserved. … … 44 44 end Object 45 45 46 object JavaString extends String47 end JavaString46 object FlatString extends String 47 end FlatString 48 48 49 49 end -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/glue/prim/FlatString.java
r3214 r3287 1 1 /******************************************************************************* 2 Copyright 200 8Sun Microsystems, Inc.,2 Copyright 2009 Sun Microsystems, Inc., 3 3 4150 Network Circle, Santa Clara, California 95054, U.S.A. 4 4 All rights reserved. … … 35 35 36 36 37 public class JavaString extends NativeConstructor {37 public class FlatString extends NativeConstructor { 38 38 39 public JavaString(Environment env,39 public FlatString(Environment env, 40 40 FTypeObject selfType, 41 41 ObjectConstructor def) { … … 51 51 52 52 @Override 53 protected void unregister() {53 protected void unregister() { 54 54 FString.resetConstructor(); 55 55 } … … 58 58 protected abstract java.lang.String f(java.lang.String s, java.lang.String o); 59 59 @Override 60 public final FString applyMethod(FObject self, FValue other) {60 public final FString applyMethod(FObject self, FValue other) { 61 61 return FString.make(f(self.getString(),other.getString())); 62 62 } … … 66 66 protected abstract boolean f(java.lang.String s, java.lang.String o); 67 67 @Override 68 public final FBool applyMethod(FObject self, FValue other) {68 public final FBool applyMethod(FObject self, FValue other) { 69 69 return FBool.make(f(((FString)self).getString(), 70 70 ((FString)other).getString())); … … 75 75 protected abstract int f(java.lang.String s, java.lang.String o); 76 76 @Override 77 public final FInt applyMethod(FObject self, FValue other) {77 public final FInt applyMethod(FObject self, FValue other) { 78 78 return FInt.make(f(((FString)self).getString(), 79 79 ((FString)other).getString())); … … 84 84 protected abstract int f(java.lang.String s); 85 85 @Override 86 public final FInt applyMethod(FObject self) {86 public final FInt applyMethod(FObject self) { 87 87 return FInt.make(f(((FString)self).getString())); 88 88 } … … 92 92 protected abstract java.lang.String f(java.lang.String s, int lo, int hi); 93 93 @Override 94 public final FString applyMethod(FObject self, FValue lo, FValue hi) {94 public final FString applyMethod(FObject self, FValue lo, FValue hi) { 95 95 return FString.make(f(((FString)self).getString(), 96 96 ((FInt)lo).getInt(), … … 102 102 protected abstract java.lang.String f(FString s); 103 103 @Override 104 public final FString applyMethod(FObject self) {104 public final FString applyMethod(FObject self) { 105 105 return FString.make(f((FString) self)); 106 106 } … … 110 110 protected abstract char f(java.lang.String s, int i); 111 111 @Override 112 public final FChar applyMethod(FObject self, FValue i) {112 public final FChar applyMethod(FObject self, FValue i) { 113 113 return FChar.make(f(((FString)self).getString(), 114 114 ((FInt)i).getInt())); … … 119 119 protected abstract int f(java.lang.String s, int c); 120 120 @Override 121 public final FInt applyMethod(FObject self, FValue c) {121 public final FInt applyMethod(FObject self, FValue c) { 122 122 return FInt.make(f(((FString)self).getString(), 123 123 ((FChar)c).getChar())); … … 127 127 public static final class Size extends s2I { 128 128 @Override 129 protected int f(java.lang.String s) {129 protected int f(java.lang.String s) { 130 130 return s.length(); 131 131 } … … 134 134 public static final class Eq extends ss2B { 135 135 @Override 136 protected boolean f(java.lang.String self, java.lang.String other) {136 protected boolean f(java.lang.String self, java.lang.String other) { 137 137 return self.equals(other); 138 138 } … … 141 141 public static final class Cmp extends ss2I { 142 142 @Override 143 protected int f(java.lang.String self, java.lang.String other) {143 protected int f(java.lang.String self, java.lang.String other) { 144 144 return self.compareTo(other); 145 145 } … … 148 148 public static final class CICmp extends ss2I { 149 149 @Override 150 protected int f(java.lang.String self, java.lang.String other) {150 protected int f(java.lang.String self, java.lang.String other) { 151 151 return self.compareToIgnoreCase(other); 152 152 } … … 155 155 public static final class Substr extends sII2s { 156 156 @Override 157 protected java.lang.String f(java.lang.String self, int x, int y) {157 protected java.lang.String f(java.lang.String self, int x, int y) { 158 158 return self.substring(x,y); 159 159 } … … 162 162 public static final class ToString extends s2s { 163 163 @Override 164 protected java.lang.String f(FString self) {164 protected java.lang.String f(FString self) { 165 165 return self.toString(); 166 166 } … … 169 169 public static final class Index extends sI2C { 170 170 @Override 171 protected char f(java.lang.String self, int i) {171 protected char f(java.lang.String self, int i) { 172 172 return self.charAt(i); 173 173 } … … 176 176 public static final class Concat extends ss2S { 177 177 @Override 178 protected java.lang.String f(java.lang.String x, java.lang.String y) {178 protected java.lang.String f(java.lang.String x, java.lang.String y) { 179 179 return x + y; 180 180 } … … 183 183 public static final class IndexOf extends sC2I { 184 184 @Override 185 protected int f(java.lang.String s, int c) {185 protected int f(java.lang.String s, int c) { 186 186 return s.indexOf((char)c); 187 187 } -
trunk/ProjectFortress/tests/LongStringTests.fss
r3196 r3287 1 1 (******************************************************************************* 2 Copyright 200 8Sun Microsystems, Inc.,2 Copyright 2009 Sun Microsystems, Inc., 3 3 4150 Network Circle, Santa Clara, California 95054, U.S.A. 4 4 All rights reserved. … … 24 24 export Testable 25 25 26 var fileContents: String := ""27 var longSourceString: String := ""26 var fileContents: String := "" 27 var longSourceString: String := "" 28 28 29 test inputTest(): () = do30 readFile(10)31 (*32 println ""33 println "fileContents is a " fileContents.ilkName34 println "length = " fileContents.size35 println "depth = " fileContents.depth36 println ( if fileContents.isBalanced then37 "balanced"38 elif fileContents.isAlmostBalanced then39 "almost balanced"40 else41 "unbalanced"42 end )43 *)29 test inputTest(): () = do 30 readFile(10) 31 (* 32 println "" 33 println "fileContents is a " fileContents.ilkName 34 println "length = " fileContents.size 35 println "depth = " fileContents.depth 36 println ( if fileContents.isBalanced then 37 "balanced" 38 elif fileContents.isAlmostBalanced then 39 "almost balanced" 40 else 41 "unbalanced" 42 end ) 43 *) 44 44 45 balancedContents = fileContents.balanced() 46 assert(balancedContents, fileContents) 47 (* 48 println "balancedContents is a " balancedContents.ilkName 49 println "length = " balancedContents.size 50 println "depth = " balancedContents.depth 51 println ( if balancedContents.isBalanced then 52 "balanced" 53 elif balancedContents.isAlmostBalanced then 54 "almost balanced" 55 else 56 "unbalanced" 57 end ) 58 output = FileWriteStream(getEnvironment("fortress.autohome", ".") "/ProjectFortress/tests/poem.out") 59 output.write(balancedContents) 60 output.close() 61 *) 45 balancedContents = fileContents.balanced() 46 assert(balancedContents, fileContents) 47 (* 48 println "balancedContents is a " balancedContents.ilkName 49 println "length = " balancedContents.size 50 println "depth = " balancedContents.depth 51 println ( if balancedContents.isBalanced then 52 "balanced" 53 elif balancedContents.isAlmostBalanced then 54 "almost balanced" 55 else 56 "unbalanced" 57 end ) 58 output = FileWriteStream(getEnvironment("fortress.autohome", ".") "/ProjectFortress/tests/poem.out") 59 output.write(balancedContents) 60 output.close() 61 *) 62 end 63 64 readFile(n: ZZ32): () = do 65 input = FileReadStream(getEnvironment("fortress.autohome", ".") "/ProjectFortress/tests/poem.txt") 66 maxLeafSize := n 67 fileContents := BIG || [ c ← seq(input.chunks(n)) ] c 68 input.close() 69 longSourceString := fileContents.asFlatString 70 (* for i ← seq(1:4) do 71 longSourceString := longSourceString || longSourceString 62 72 end 73 longSourceString := longSourceString.asFlatString *) 74 end 63 75 64 readFile(n: ZZ32): () = do 65 input = FileReadStream(getEnvironment("fortress.autohome", ".") "/ProjectFortress/tests/poem.txt") 66 maxLeafSize := n 67 fileContents := BIG || [ c ← seq(input.chunks(n)) ] c 68 input.close() 69 longSourceString := fileContents.asJavaString 70 (* for i ← seq(1:4) do 71 longSourceString := longSourceString || longSourceString 72 end 73 longSourceString := longSourceString.asJavaString *) 76 buildString(n: ZZ32): () = do 77 if longSourceString.isEmpty then readFile(128) end 78 maxLeafSize := n 79 fileContents := BIG || [ i ← longSourceString.indices ] longSourceString[i] 80 end 81 82 test miniTest() = do 83 maxLeafSize := 10 84 abcdef = CatString("a", CatString("b", CatString("c", CatString("d", 85 CatString(EmptyString, CatString("e", "f")))))) 86 assert(abcdef, "abcdef") 87 balancedAbcdef = abcdef.balanced() 88 assert(balancedAbcdef, "abcdef") 89 assert(abcdef.asDebugString, "bC6/6:" // 90 " J1/0:a" // 91 " BC5/5:" // 92 " J1/0:b" // 93 " BC4/4:" // 94 " J1/0:c" // 95 " BC3/3:" // 96 " J1/0:d" // 97 " BC2/2:" // 98 " E0/0" // 99 " BC2/1:" // 100 " J1/0:e" // 101 " J1/0:f") 102 assert(balancedAbcdef.asDebugString, "J6/0:abcdef") 103 end 104 105 test statsTest() = do 106 buildString(6) 107 ss = fileContents.stats() 108 println (// ss.asString) 109 assert(ss.ssize, fileContents.size) 110 assert(ss.maxFlat, 4) 111 assert(ss.minFlat, 4) 112 assert(ss.avFlat, 4) 113 assert(ss.numFlat, 353) 114 end 115 116 test buildTiming() = do 117 println () 118 for t ← seq(⟨8, 16, 32, 64 (*, 128, 256, 512, 1024 *)⟩) do 119 ("MaxFlat = " || t || ": ") PRINTTIME: buildString(t) 120 println(fileContents.stats()) 74 121 end 122 end 75 123 76 buildString(n: ZZ32): () = do 77 if longSourceString.isEmpty then readFile(128) end 78 maxLeafSize := n 79 fileContents := BIG || [ i ← longSourceString.indices ] longSourceString[i] 124 test generatorTest() = do 125 "sequential" PRINTTIME: tryGen(⟨7, 9, 17 , 36, 98, 274, 1020, 2030⟩, seq) 126 "concurrent" PRINTTIME: tryGen(⟨7, 9, 17 , 36, 98, 274, 1020, 2030⟩, identity⟦Generator⟦Int⟧⟧) 127 end 128 129 tryGen(endpoints, f) = do 130 if fileContents.isEmpty then readFile(29) end 131 m = |fileContents| 132 println (newline fileContents.stats()) 133 for i ← f(endpoints), j ← f(endpoints), j MOD m ≥ i MOD m do 134 (*) println "subrange [" (i MOD m) ":" (j MOD m) "]" 135 (*) println fileContents[(i MOD m):(j MOD m)].asDebugString 136 assert(BIG || [ ch ←fileContents[(i MOD m):(j MOD m)]] ch, 137 fileContents[(i MOD m):(j MOD m)], 138 "when comparing subrange [" (i MOD m) ":" (j MOD m) "]") 80 139 end 140 end 81 141 82 test miniTest() = do 83 maxLeafSize := 10 84 abcdef = CatString("a", CatString("b", CatString("c", CatString("d", 85 CatString(EmptyString, CatString("e", "f")))))) 86 assert(abcdef, "abcdef") 87 balancedAbcdef = abcdef.balanced() 88 assert(balancedAbcdef, "abcdef") 89 assert(abcdef.asDebugString, "bC6/6:" // 90 " J1/0:a" // 91 " BC5/5:" // 92 " J1/0:b" // 93 " BC4/4:" // 94 " J1/0:c" // 95 " BC3/3:" // 96 " J1/0:d" // 97 " BC2/2:" // 98 " E0/0" // 99 " BC2/1:" // 100 " J1/0:e" // 101 " J1/0:f") 102 assert(balancedAbcdef.asDebugString, "J6/0:abcdef") 103 end 104 105 test statsTest() = do 106 buildString(6) 107 ss = fileContents.stats() 108 println (// ss.asString) 109 assert(ss.ssize, fileContents.size) 110 assert(ss.maxFlat, 4) 111 assert(ss.minFlat, 4) 112 assert(ss.avFlat, 4) 113 assert(ss.numFlat, 353) 114 end 115 116 test buildTiming() = do 117 println () 118 for t ← seq(⟨8, 16, 32, 64 (*, 128, 256, 512, 1024 *)⟩) do 119 ("MaxFlat = " || t || ": ") PRINTTIME: buildString(t) 120 println(fileContents.stats()) 121 end 122 end 123 124 test generatorTest() = do 125 "sequential" PRINTTIME: tryGen(⟨7, 9, 17 , 36, 98, 274, 1020, 2030⟩, seq) 126 "concurrent" PRINTTIME: tryGen(⟨7, 9, 17 , 36, 98, 274, 1020, 2030⟩, identity⟦Generator⟦Int⟧⟧) 127 end 128 129 tryGen(endpoints, f) = do 130 if fileContents.isEmpty then readFile(29) end 131 m = |fileContents| 132 println (newline fileContents.stats()) 133 for i ← f(endpoints), j ← f(endpoints), j MOD m ≥ i MOD m do 134 (*) println "subrange [" (i MOD m) ":" (j MOD m) "]" 135 (*) println fileContents[(i MOD m):(j MOD m)].asDebugString 136 assert(BIG || [ ch ←fileContents[(i MOD m):(j MOD m)]] ch, 137 fileContents[(i MOD m):(j MOD m)], 138 "when comparing subrange [" (i MOD m) ":" (j MOD m) "]") 139 end 140 end 141 142 run(args:String...):() = label runMethod 143 readFile(32) 144 println fileContents 145 miniTest() 146 tryGen(⟨7, 9, 17 , 36, 275, 1032⟩, identity⟦Generator⟦Int⟧⟧) 147 end runMethod 142 run(args:String...):() = label runMethod 143 readFile(32) 144 println fileContents 145 miniTest() 146 tryGen(⟨7, 9, 17 , 36, 275, 1032⟩, identity⟦Generator⟦Int⟧⟧) 147 end runMethod 148 148 149 149 end LongStringTests -
trunk/ProjectFortress/tests/StringTests.fss
r3061 r3287 1 1 (******************************************************************************* 2 Copyright 200 8Sun Microsystems, Inc.,2 Copyright 2009 Sun Microsystems, Inc., 3 3 4150 Network Circle, Santa Clara, California 95054, U.S.A. 4 4 All rights reserved. … … 17 17 18 18 component StringTests 19 import String.{...}20 import JavaString.{...}21 import Set.{...}22 import List.{...}23 export Executable24 25 test testDepth(): () = do26 words = ⟨"Hello ", "world, ", "it's ", "a ", "bright ", "new ", "day."⟩27 var result: String = EmptyString28 for w ← seq(words) do result := CatString(result, w) end29 assert(result, "Hello world, it's a bright new day.")30 result.verify()31 assert(result.depth, 7)32 end 33 34 test testindexing(): () = do35 words = ⟨"The", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "dog."⟩36 var testString: String = EmptyString37 for w ← seq(words) do testString := CatString(testString, w) end38 referenceString = "Thequickbrownfoxjumpedoverthelazydog."39 assert(testString, referenceString)40 for i ← ⟨ 0, 5, 7, 8, 9, 36, 23, 35 ⟩ do41 assert(testString[i], referenceString[i])42 end43 for i ← ⟨ -1, -5, 37, 38, 109 ⟩ do44 shouldRaise⟦IndexOutOfBounds⟦ZZ32⟧⟧ (fn() => testString[i])45 end46 end47 48 49 test testSubString(): () = do50 words = ⟨"The", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "dog."⟩51 var testString: String = EmptyString52 for w ← seq(words) do testString := CatString(testString, w) end53 referenceString = "Thequickbrownfoxjumpedoverthelazydog."54 assert(testString, referenceString)55 for i ← ⟨ 0, 5, 7, 8, 9, 36, 23, 35 ⟩,56 j ← ⟨ 0, 5, 7, 8, 9, 36, 23, 35 ⟩ do57 assert(testString[i:j], referenceString[i:j])58 end59 end60 61 test testSubStringSimplification():() = do62 testString = catStringFrom("The", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "dog.")63 testString.verify()64 sub1 = testString[34:36]65 typecase sub1 of66 JavaString => assert(true)67 String => do68 println sub1.asDebugString69 fail "sub1=" sub1 " is not a JavaString"70 end71 end72 end73 74 75 validatesplitWithOffsets(subject: String, division): () = do76 var len: ZZ32 = 077 var accum: String = ""78 for (start, str) ← division do79 assert(start, len, str)80 len := len + |str|81 accum := accum || str82 end83 assert(len, |subject|)84 assert(accum, subject)85 end86 87 test testIlk() = do88 hello = "Hello"89 assert(hello.ilkName, "JavaString")90 hw = CatString(hello, " World")91 assert(hw.ilkName, "CatString")92 end93 94 95 test testCatStringGet() = do96 cat = CatString("@ab", "cdef")97 assert(cat.get(1), 'a')98 assert(cat.get(4), 'd')99 end100 101 test testSubstringGet() = do102 cat = CatString("@ab", "cdefg")103 subC = cat[2#4]104 assert(subC.ilkName, "SubString", subC, " is not a SubString")105 subC.verify()106 assert(cat[2], 'b')107 assert(subC[0], 'b')108 assert(subC[1], 'c')109 assert(subC[2], 'd')110 assert(subC[3], 'e')111 shouldRaise⟦IndexOutOfBounds⟦ZZ32⟧⟧ (fn() ⇒ subC[4])112 end113 114 test testJavaStringification() = do115 e = EmptyString116 assert(e.asJavaString, "", "EmptyString.javaString")117 c = CatString("abcd", "efgh")118 c.verify119 assert(c.asJavaString, "abcdefgh", "CatString.javaString")120 s = c[2:5]121 s.verify()122 assert(s.asJavaString, "cdef", "SubString.javaString")123 ss = s[1:2]124 ss.verify()125 assert(ss.asJavaString, "de", "Substring of SubString.javaString")126 lss = s[0:1]127 lss.verify()128 assert(lss.asDebugString, "J2/0:cd")129 assert(lss.asJavaString, "cd", "left Substring of SubString.javaString")130 end 131 132 test testIN() = do133 e = EmptyString134 deny('x' IN e)135 c = CatString("abcd", "efgh")136 assert('a' IN c)137 assert('f' IN c)138 deny('j' IN c)139 s = c[2:5]140 deny('a' IN s)141 assert('d' IN s)142 assert('f' IN s)143 ss = s[1:2]144 assert('e' IN ss)145 assert('d' IN ss)146 deny('f' IN ss)147 lss = s[0:1]148 assert('c' IN lss)149 deny('e' IN lss)150 assert('d' IN lss)151 end152 153 154 test testsplitWithOffsets():() = do155 subject = CatString("abcd", "efgh")156 substr1 = subject[2:6]157 validatesplitWithOffsets(substr1, seq(substr1.splitWithOffsets()))158 159 substr2 = subject[4:6]160 assert(substr2.splitWithOffsets().isEmpty, "subject[4:6].splitWithOffsets is not empty!")161 162 substr3 = subject[0:5]163 validatesplitWithOffsets(substr3, seq(substr3.splitWithOffsets()))164 165 166 subC = (CatString("@ab", "cdefg"))[2#4]167 validatesplitWithOffsets(subC, seq(subC.splitWithOffsets()))168 end 169 170 171 test testComparison():() = do172 smaller = catStringFrom("The", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "dog.")173 bigger = catStringFrom("The", "quick", "brown", "jumped", "fox", "over", "the", "lazy", "doggie.")174 smallerFlat = smaller.asJavaString175 biggerFlat = bigger.asJavaString176 smaller.verify177 bigger.verify178 assert(smaller < bigger)179 assert(smallerFlat < bigger)180 assert(smallerFlat < biggerFlat)181 assert(bigger > smaller)182 assert(smaller[10:] < bigger[10:])183 assert(bigger[12:] > smaller[12:])184 assert(biggerFlat[12:] > smaller[12:])185 a = smaller[30:36]186 b = bigger[30:36]187 a.verify188 b.verify189 assert(smaller[30#6], bigger[30:35], smaller[30#6] " is not = to " bigger[30:35])190 assert(smallerFlat[30#6], bigger[30:35], smallerFlat[30#6] " is not = to " bigger[30:35])191 end192 193 194 test testCIComparison():() = do195 smaller = catStringFrom("The", "quick", "BROWN", "fox", "jumped", "over", "the", "lazy", "dog.")196 bigger = catStringFrom("The", "QUICK", "brown", "JUMPED", "fox", "over", "the", "lazy", "doggie.")197 smallerFlat = smaller.asJavaString198 biggerFlat = bigger.asJavaString199 smaller.verify200 bigger.verify201 assert(smaller CASE_INSENSITIVE_CMP bigger, LessThan)202 assert(smallerFlat CASE_INSENSITIVE_CMP bigger, LessThan)203 assert(smallerFlat CASE_INSENSITIVE_CMP biggerFlat, LessThan)204 assert(bigger CASE_INSENSITIVE_CMP smaller, GreaterThan)205 assert(smaller[10:] CASE_INSENSITIVE_CMP bigger[10:], LessThan)206 assert(bigger[12:] CASE_INSENSITIVE_CMP smaller[12:], GreaterThan)207 assert(biggerFlat[12:] CASE_INSENSITIVE_CMP smaller[12:], GreaterThan)208 end209 210 object CatStringReduction extends MonoidReduction[\String\]211 getter asString() = "CatString Reduction"212 empty(): String = EmptyString213 join(a:String, b:String):String = CatString(a, b)214 end215 216 catStringFrom(args: String...): String =217 seq(args).generate⟦String⟧(CatStringReduction, fn(x) => x)218 219 220 test testNonEmptyConcat(): () = do221 stuff = "Hello "222 more = "World"223 hw = CatString(stuff, more)224 assert(|hw|, |stuff| + |more|)225 assert(hw, "Hello World")226 assert(hw, CatString("Hell", "o World"))227 end228 229 test testEmptyConcat(): () = do230 e = EmptyString231 assert(|e|, 0)232 assert(e.isEmpty)233 stuff = "Hello "234 more = "World"235 h = CatString(stuff, e)236 assert(|h|, |stuff|)237 assert(stuff || e, stuff)238 end 239 240 test testCharConcat(): () = do241 var result: String = EmptyString242 hw = "Hello World"243 for c <- seq(hw) do244 result := result || c245 end246 assert(result, hw)247 end 248 249 test testParallelGenerator(): () = do250 chars = "abcdefghijklmnopqrstuvwxyz"251 var result: Set⟦Char⟧ = set⟦Char⟧()252 for c ← chars atomic do result := result.add(c) end253 assert(|result|, |chars|)254 for c ← result do assert(c ∈ chars) end255 end 256 257 test testSequentialGenerator(): () = do258 chars = "abcdefghijklmnopqrstuvwxyz"259 var result: List⟦Char⟧ = emptyList⟦Char⟧(26)260 for c ← seq(chars) do result := result.addRight(c) end261 assert(|result|, |chars|)262 for i ← result.bounds do assert(result[i] , chars[i]) end263 end 264 265 test testEquality() = do266 subJ = "bcdefg"[1#4]267 subC = (CatString("@ab", "cdefg"))[2#4]268 assert(subJ > subC, "cdef not > bcde")269 assert("abcdefg"[1#4], subC)270 end271 272 test testStringification() = do273 str = CatString("The word \"test\"", " is overused")274 ran = 1:20:2275 assert(str.asString, str)276 assert(str.asExprString, "\"The word \\\"test\\\" is overused\"")277 assert(str.asDebugString, "BC27/1:"//278 " J15/0:The word \"test\""//279 " J12/0: is overused") 280 assert((CatString(str[#11], str[13:])).asExprString, "\"The word \\\"tt\\\" is overused\"")281 assert(ran.asString, "[1,3,5,7,... 19]")282 assert(ran.asExprString, "1:19:2")283 assert(ran.asDebugString, "StridedFullParScalarRange(1,19,2)")284 end285 286 run(args:String...):() = do287 testStringification()288 testDepth()289 testindexing()290 testSubString()291 testSubStringSimplification()292 testIlk()293 testJavaStringification()294 testsplitWithOffsets()295 testIN()296 testComparison()297 testCIComparison()298 testNonEmptyConcat()299 testEmptyConcat()300 testCharConcat()301 testParallelGenerator()302 testSequentialGenerator()303 testCatStringGet()304 testSubstringGet()305 testEquality()306 end19 import String.{...} 20 import FlatString.{...} 21 import Set.{...} 22 import List.{...} 23 export Executable 24 25 test testDepth(): () = do 26 words = ⟨"Hello ", "world, ", "it's ", "a ", "bright ", "new ", "day."⟩ 27 var result: String = EmptyString 28 for w ← seq(words) do result := CatString(result, w) end 29 assert(result, "Hello world, it's a bright new day.") 30 result.verify() 31 assert(result.depth, 7) 32 end 33 34 test testindexing(): () = do 35 words = ⟨"The", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "dog."⟩ 36 var testString: String = EmptyString 37 for w ← seq(words) do testString := CatString(testString, w) end 38 referenceString = "Thequickbrownfoxjumpedoverthelazydog." 39 assert(testString, referenceString) 40 for i ← ⟨ 0, 5, 7, 8, 9, 36, 23, 35 ⟩ do 41 assert(testString[i], referenceString[i]) 42 end 43 for i ← ⟨ -1, -5, 37, 38, 109 ⟩ do 44 shouldRaise⟦IndexOutOfBounds⟦ZZ32⟧⟧ (fn() => testString[i]) 45 end 46 end 47 48 49 test testSubString(): () = do 50 words = ⟨"The", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "dog."⟩ 51 var testString: String = EmptyString 52 for w ← seq(words) do testString := CatString(testString, w) end 53 referenceString = "Thequickbrownfoxjumpedoverthelazydog." 54 assert(testString, referenceString) 55 for i ← ⟨ 0, 5, 7, 8, 9, 36, 23, 35 ⟩, 56 j ← ⟨ 0, 5, 7, 8, 9, 36, 23, 35 ⟩ do 57 assert(testString[i:j], referenceString[i:j]) 58 end 59 end 60 61 test testSubStringSimplification():() = do 62 testString = catStringFrom("The", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "dog.") 63 testString.verify() 64 sub1 = testString[34:36] 65 typecase sub1 of 66 FlatString => assert(true) 67 String => do 68 println sub1.asDebugString 69 fail "sub1=" sub1 " is not a FlatString" 70 end 71 end 72 end 73 74 75 validatesplitWithOffsets(subject: String, division): () = do 76 var len: ZZ32 = 0 77 var accum: String = "" 78 for (start, str) ← division do 79 assert(start, len, str) 80 len := len + |str| 81 accum := accum || str 82 end 83 assert(len, |subject|) 84 assert(accum, subject) 85 end 86 87 test testIlk() = do 88 hello = "Hello" 89 assert(hello.ilkName, "FlatString") 90 hw = CatString(hello, " World") 91 assert(hw.ilkName, "CatString") 92 end 93 94 95 test testCatStringGet() = do 96 cat = CatString("@ab", "cdef") 97 assert(cat.get(1), 'a') 98 assert(cat.get(4), 'd') 99 end 100 101 test testSubstringGet() = do 102 cat = CatString("@ab", "cdefg") 103 subC = cat[2#4] 104 assert(subC.ilkName, "SubString", subC, " is not a SubString") 105 subC.verify() 106 assert(cat[2], 'b') 107 assert(subC[0], 'b') 108 assert(subC[1], 'c') 109 assert(subC[2], 'd') 110 assert(subC[3], 'e') 111 shouldRaise⟦IndexOutOfBounds⟦ZZ32⟧⟧ (fn() ⇒ subC[4]) 112 end 113 114 test testFlatStringification() = do 115 e = EmptyString 116 assert(e.asFlatString, "", "EmptyString.javaString") 117 c = CatString("abcd", "efgh") 118 c.verify 119 assert(c.asFlatString, "abcdefgh", "CatString.javaString") 120 s = c[2:5] 121 s.verify() 122 assert(s.asFlatString, "cdef", "SubString.javaString") 123 ss = s[1:2] 124 ss.verify() 125 assert(ss.asFlatString, "de", "Substring of SubString.javaString") 126 lss = s[0:1] 127 lss.verify() 128 assert(lss.asDebugString, "J2/0:cd") 129 assert(lss.asFlatString, "cd", "left Substring of SubString.javaString") 130 end 131 132 test testIN() = do 133 e = EmptyString 134 deny('x' IN e) 135 c = CatString("abcd", "efgh") 136 assert('a' IN c) 137 assert('f' IN c) 138 deny('j' IN c) 139 s = c[2:5] 140 deny('a' IN s) 141 assert('d' IN s) 142 assert('f' IN s) 143 ss = s[1:2] 144 assert('e' IN ss) 145 assert('d' IN ss) 146 deny('f' IN ss) 147 lss = s[0:1] 148 assert('c' IN lss) 149 deny('e' IN lss) 150 assert('d' IN lss) 151 end 152 153 154 test testsplitWithOffsets():() = do 155 subject = CatString("abcd", "efgh") 156 substr1 = subject[2:6] 157 validatesplitWithOffsets(substr1, seq(substr1.splitWithOffsets())) 158 159 substr2 = subject[4:6] 160 assert(substr2.splitWithOffsets().isEmpty, "subject[4:6].splitWithOffsets is not empty!") 161 162 substr3 = subject[0:5] 163 validatesplitWithOffsets(substr3, seq(substr3.splitWithOffsets())) 164 165 166 subC = (CatString("@ab", "cdefg"))[2#4] 167 validatesplitWithOffsets(subC, seq(subC.splitWithOffsets())) 168 end 169 170 171 test testComparison():() = do 172 smaller = catStringFrom("The", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "dog.") 173 bigger = catStringFrom("The", "quick", "brown", "jumped", "fox", "over", "the", "lazy", "doggie.") 174 smallerFlat = smaller.asFlatString 175 biggerFlat = bigger.asFlatString 176 smaller.verify 177 bigger.verify 178 assert(smaller < bigger) 179 assert(smallerFlat < bigger) 180 assert(smallerFlat < biggerFlat) 181 assert(bigger > smaller) 182 assert(smaller[10:] < bigger[10:]) 183 assert(bigger[12:] > smaller[12:]) 184 assert(biggerFlat[12:] > smaller[12:]) 185 a = smaller[30:36] 186 b = bigger[30:36] 187 a.verify 188 b.verify 189 assert(smaller[30#6], bigger[30:35], smaller[30#6] " is not = to " bigger[30:35]) 190 assert(smallerFlat[30#6], bigger[30:35], smallerFlat[30#6] " is not = to " bigger[30:35]) 191 end 192 193 194 test testCIComparison():() = do 195 smaller = catStringFrom("The", "quick", "BROWN", "fox", "jumped", "over", "the", "lazy", "dog.") 196 bigger = catStringFrom("The", "QUICK", "brown", "JUMPED", "fox", "over", "the", "lazy", "doggie.") 197 smallerFlat = smaller.asFlatString 198 biggerFlat = bigger.asFlatString 199 smaller.verify 200 bigger.verify 201 assert(smaller CASE_INSENSITIVE_CMP bigger, LessThan) 202 assert(smallerFlat CASE_INSENSITIVE_CMP bigger, LessThan) 203 assert(smallerFlat CASE_INSENSITIVE_CMP biggerFlat, LessThan) 204 assert(bigger CASE_INSENSITIVE_CMP smaller, GreaterThan) 205 assert(smaller[10:] CASE_INSENSITIVE_CMP bigger[10:], LessThan) 206 assert(bigger[12:] CASE_INSENSITIVE_CMP smaller[12:], GreaterThan) 207 assert(biggerFlat[12:] CASE_INSENSITIVE_CMP smaller[12:], GreaterThan) 208 end 209 210 object CatStringReduction extends MonoidReduction[\String\] 211 getter asString() = "CatString Reduction" 212 empty(): String = EmptyString 213 join(a:String, b:String):String = CatString(a, b) 214 end 215 216 catStringFrom(args: String...): String = 217 seq(args).generate⟦String⟧(CatStringReduction, fn(x) => x) 218 219 220 test testNonEmptyConcat(): () = do 221 stuff = "Hello " 222 more = "World" 223 hw = CatString(stuff, more) 224 assert(|hw|, |stuff| + |more|) 225 assert(hw, "Hello World") 226 assert(hw, CatString("Hell", "o World")) 227 end 228 229 test testEmptyConcat(): () = do 230 e = EmptyString 231 assert(|e|, 0) 232 assert(e.isEmpty) 233 stuff = "Hello " 234 more = "World" 235 h = CatString(stuff, e) 236 assert(|h|, |stuff|) 237 assert(stuff || e, stuff) 238 end 239 240 test testCharConcat(): () = do 241 var result: String = EmptyString 242 hw = "Hello World" 243 for c <- seq(hw) do 244 result := result || c 245 end 246 assert(result, hw) 247 end 248 249 test testParallelGenerator(): () = do 250 chars = "abcdefghijklmnopqrstuvwxyz" 251 var result: Set⟦Char⟧ = set⟦Char⟧() 252 for c ← chars atomic do result := result.add(c) end 253 assert(|result|, |chars|) 254 for c ← result do assert(c ∈ chars) end 255 end 256 257 test testSequentialGenerator(): () = do 258 chars = "abcdefghijklmnopqrstuvwxyz" 259 var result: List⟦Char⟧ = emptyList⟦Char⟧(26) 260 for c ← seq(chars) do result := result.addRight(c) end 261 assert(|result|, |chars|) 262 for i ← result.bounds do assert(result[i] , chars[i]) end 263 end 264 265 test testEquality() = do 266 subJ = "bcdefg"[1#4] 267 subC = (CatString("@ab", "cdefg"))[2#4] 268 assert(subJ > subC, "cdef not > bcde") 269 assert("abcdefg"[1#4], subC) 270 end 271 272 test testStringification() = do 273 str = CatString("The word \"test\"", " is overused") 274 ran = 1:20:2 275 assert(str.asString, str) 276 assert(str.asExprString, "\"The word \\\"test\\\" is overused\"") 277 assert(str.asDebugString, "BC27/1:"// 278 " J15/0:The word \"test\""// 279 " J12/0: is overused") 280 assert((CatString(str[#11], str[13:])).asExprString, "\"The word \\\"tt\\\" is overused\"") 281 assert(ran.asString, "[1,3,5,7,... 19]") 282 assert(ran.asExprString, "1:19:2") 283 assert(ran.asDebugString, "StridedFullParScalarRange(1,19,2)") 284 end 285 286 run(args:String...):() = do 287 testStringification() 288 testDepth() 289 testindexing() 290 testSubString() 291 testSubStringSimplification() 292 testIlk() 293 testFlatStringification() 294 testsplitWithOffsets() 295 testIN() 296 testComparison() 297 testCIComparison() 298 testNonEmptyConcat() 299 testEmptyConcat() 300 testCharConcat() 301 testParallelGenerator() 302 testSequentialGenerator() 303 testCatStringGet() 304 testSubstringGet() 305 testEquality() 306 end 307 307 308 308 end StringTests -
trunk/Sandbox/FlatStringIsGenerator.fss
r2635 r3287 1 component JavaStringIsGenerator1 component FlatStringIsGenerator 2 2 (* 3 import JavaString.{...}3 import FlatString.{...} 4 4 *) 5 5 export Executable … … 22 22 (* 23 23 typecase chs="Hell" of 24 JavaString => println "Hell is a JavaString"25 else => println "Hell is NOT a JavaString"24 FlatString => println "Hell is a FlatString" 25 else => println "Hell is NOT a FlatString" 26 26 end 27 27 *)

