Add typed Kotlin string comparison
ober
bebe21de07a4914bf63d1419a29a18b739f65e86
--- a/lib/jerboa/typed/checker.ss +++ b/lib/jerboa/typed/checker.ss @@ -503,6 +503,9 @@ (cons 'string-blank? (make-typed-call-sig (list 'String) 'Bool '() 'jvm-string-blank '())) + (cons 'string-compare-to + (make-typed-call-sig (list 'String 'String) 'Int32 '() + 'jvm-string-compare-to '())) (cons 'url-encode-utf8 (make-typed-call-sig (list 'String) 'String '() 'jvm-url-encode-utf8 '())) --- a/lib/jerboa/typed/core.ss +++ b/lib/jerboa/typed/core.ss @@ -170,6 +170,7 @@ jvm-json-object-opt-int32-default jvm-json-object-opt-json-array jvm-json-object-opt-json-object + jvm-string-compare-to jvm-string-substring-before jvm-system-current-time-millis-string record-ctor --- a/lib/jerboa/typed/kotlin/lower.ss +++ b/lib/jerboa/typed/kotlin/lower.ss @@ -311,6 +311,8 @@ (make-kt-member-call (car args) 'endsWith (cdr args))] [(jvm-string-blank) (make-kt-member-call (car args) 'isBlank '())] + [(jvm-string-compare-to) + (make-kt-member-call (car args) 'compareTo (cdr args))] [(jvm-url-encode-utf8) (make-kt-call (make-kt-name '(java net URLEncoder encode)) --- a/tests/test-typed-kotlin.ss +++ b/tests/test-typed-kotlin.ss @@ -909,7 +909,7 @@ (define ocr-string-form '(typed-library (sample typed ocrstrings) - (export normalizeOcr compact shouldReplaceOcrLabel) + (export normalizeOcr compact compareLabels shouldReplaceOcrLabel) (type Int32) (def (normalizeOcr (value : String)) : String (string-replace-regex @@ -926,6 +926,8 @@ (url-encode-utf8 value)) (def (idNumber (value : String)) : (Nullable Int32) (string->int32-or-null (string-remove-prefix value "c"))) + (def (compareLabels (a : String) (b : String)) : Int32 + (string-compare-to (string-lowercase a) (string-lowercase b))) (def (shouldReplaceOcrLabel (label : String) (status : String) (notes : String)) : Bool (let ((text (string-trim label))) (if (string-blank? text) @@ -959,6 +961,8 @@ "Regex(\"^\\\\d+\\\\s+boxes$\").matches(text)") (test-contains "String startsWith lowers to Kotlin startsWith" ocr-string-kotlin "notes.startsWith(\"Guess:\")") +(test-contains "String compare-to lowers to Kotlin compareTo" ocr-string-kotlin + "a.lowercase().compareTo(b.lowercase())") (printf "typed-kotlin tests: ~a passed, ~a failed~%" pass fail) (when (> fail 0) (exit 1))