From 6e995b6303153c1df78babda23980fade70a4749 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=82=8E=E5=9F=8E?= <15371716+David-Yancheng-Li@user.noreply.gitee.com> Date: Sat, 1 Feb 2025 10:56:21 +0800 Subject: [PATCH 1/2] submit --- GoldfishLang.tmu | 44 ++++++++++++++++++++++++++++--- goldfish/liii/lang.scm | 8 +++++- tests/goldfish/liii/lang-test.scm | 12 +++++++++ 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/GoldfishLang.tmu b/GoldfishLang.tmu index 66f5fae3..fa101d29 100644 --- a/GoldfishLang.tmu +++ b/GoldfishLang.tmu @@ -1,6 +1,6 @@ -> +> -> +> <\body> <\hide-preamble> @@ -102,7 +102,7 @@ \ \ rich-list rich-vector rich-hash-table - \ \ box + \ \ box\ ) @@ -1343,7 +1343,7 @@ - + tring> <\goldfish-chunk|goldfish/liii/lang.scm|true|true> (define (%to-string) @@ -1359,6 +1359,42 @@ \; + + + <\goldfish-chunk|goldfish/liii/lang.scm|true|true> + (define (%strip-prefix prefix) + + \ \ (if (and (\= (string-length data) (string-length prefix)) + + \ \ \ \ \ \ \ \ \ \ \ (string=? (substring data 0 (string-length prefix)) prefix)) + + \ \ \ \ \ \ (rich-string (substring data (string-length prefix))) + + \ \ \ \ \ \ (rich-string data))) + + \ + + + <\goldfish-chunk|tests/goldfish/liii/lang-test.scm|true|true> + (check ((rich-string "hello"):strip-prefix "he") =\ (rich-string "llo")) + + (check ((rich-string "hello"):strip-prefix "hello") =\ (rich-string "")) + + (check ((rich-string "hello"):strip-prefix "abc") =\ (rich-string "hello")) + + (check ((rich-string "hello"):strip-prefix "helloo") =\ (rich-string "hello")) + + (check (((rich-string "hello"):strip-prefix "he"):strip-prefix "ll") =\ (rich-string "o")) + + \; + + (check-catch 'wrong-number-of-args ("hello":strip-prefix "he")) + + (check-catch 'unbound-variable (123:strip-prefix 1)) + + \; + + <\scm-chunk|goldfish/liii/lang.scm|true|true> diff --git a/goldfish/liii/lang.scm b/goldfish/liii/lang.scm index 7162afe2..8877bede 100644 --- a/goldfish/liii/lang.scm +++ b/goldfish/liii/lang.scm @@ -21,7 +21,7 @@ option none rich-integer rich-char rich-string rich-list rich-vector rich-hash-table - box + box ) (begin @@ -266,6 +266,12 @@ (define (%to-string) data) +(define (%strip-prefix prefix) + (if (and (>= (string-length data) (string-length prefix)) + (string=? (substring data 0 (string-length prefix)) prefix)) + (rich-string (substring data (string-length prefix))) + (rich-string data))) + ) (define-case-class rich-list ((data list?)) diff --git a/tests/goldfish/liii/lang-test.scm b/tests/goldfish/liii/lang-test.scm index 4f1f2c5c..05bc173a 100644 --- a/tests/goldfish/liii/lang-test.scm +++ b/tests/goldfish/liii/lang-test.scm @@ -192,6 +192,18 @@ (check ((rich-string "hello") :to-string) => "hello") +(check ((rich-string "hello"):strip-prefix "he") => (rich-string "llo")) +(check ((rich-string "hello"):strip-prefix "hello") => (rich-string "")) +(check ((rich-string "hello"):strip-prefix "abc") => (rich-string "hello")) +(check ((rich-string "hello"):strip-prefix "helloo") => (rich-string "hello")) +(check (((rich-string "hello"):strip-prefix "he"):strip-prefix "ll") => (rich-string "o")) + +(check-catch 'wrong-number-of-args ("hello":strip-prefix "he")) +(check-catch 'unbound-variable (123:strip-prefix 1)) + + + + (check ((box '(1 2 3)) :apply 0) => 1) (check ((box '(1 2 3)) 0) => 1) -- Gitee From 85d5d8d83ec26e57b60b6782271c856046c16198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=82=8E=E5=9F=8E?= <15371716+David-Yancheng-Li@user.noreply.gitee.com> Date: Sat, 1 Feb 2025 12:12:51 +0800 Subject: [PATCH 2/2] submit2 --- GoldfishLang.tmu | 18 +++++++++--------- goldfish/liii/lang.scm | 2 +- tests/goldfish/liii/lang-test.scm | 19 ++++++++----------- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/GoldfishLang.tmu b/GoldfishLang.tmu index fa101d29..0c36aeac 100644 --- a/GoldfishLang.tmu +++ b/GoldfishLang.tmu @@ -102,7 +102,7 @@ \ \ rich-list rich-vector rich-hash-table - \ \ box\ + \ \ box ) @@ -1343,7 +1343,7 @@ - tring> + <\goldfish-chunk|goldfish/liii/lang.scm|true|true> (define (%to-string) @@ -1376,21 +1376,21 @@ <\goldfish-chunk|tests/goldfish/liii/lang-test.scm|true|true> - (check ((rich-string "hello"):strip-prefix "he") =\ (rich-string "llo")) + (check ((box "hello") :strip-prefix "he") =\ (box "llo")) - (check ((rich-string "hello"):strip-prefix "hello") =\ (rich-string "")) + (check ((box "hello") :strip-prefix "hello") =\ (box "")) - (check ((rich-string "hello"):strip-prefix "abc") =\ (rich-string "hello")) + (check ((box "hello") :strip-prefix "abc") =\ (box "hello")) - (check ((rich-string "hello"):strip-prefix "helloo") =\ (rich-string "hello")) + (check ((box "hello") :strip-prefix "helloo") =\ (box "hello")) - (check (((rich-string "hello"):strip-prefix "he"):strip-prefix "ll") =\ (rich-string "o")) + (check (((box "hello") :strip-prefix "he"):strip-prefix "ll") =\ (box "o")) \; - (check-catch 'wrong-number-of-args ("hello":strip-prefix "he")) + (check-catch 'wrong-number-of-args ("hello" :strip-prefix "he")) - (check-catch 'unbound-variable (123:strip-prefix 1)) + (check-catch 'syntax-error (123 :strip-prefix 1)) \; diff --git a/goldfish/liii/lang.scm b/goldfish/liii/lang.scm index 8877bede..11eae5f2 100644 --- a/goldfish/liii/lang.scm +++ b/goldfish/liii/lang.scm @@ -21,7 +21,7 @@ option none rich-integer rich-char rich-string rich-list rich-vector rich-hash-table - box + box ) (begin diff --git a/tests/goldfish/liii/lang-test.scm b/tests/goldfish/liii/lang-test.scm index 05bc173a..2c416927 100644 --- a/tests/goldfish/liii/lang-test.scm +++ b/tests/goldfish/liii/lang-test.scm @@ -192,17 +192,14 @@ (check ((rich-string "hello") :to-string) => "hello") -(check ((rich-string "hello"):strip-prefix "he") => (rich-string "llo")) -(check ((rich-string "hello"):strip-prefix "hello") => (rich-string "")) -(check ((rich-string "hello"):strip-prefix "abc") => (rich-string "hello")) -(check ((rich-string "hello"):strip-prefix "helloo") => (rich-string "hello")) -(check (((rich-string "hello"):strip-prefix "he"):strip-prefix "ll") => (rich-string "o")) - -(check-catch 'wrong-number-of-args ("hello":strip-prefix "he")) -(check-catch 'unbound-variable (123:strip-prefix 1)) - - - +(check ((box "hello") :strip-prefix "he") => (box "llo")) +(check ((box "hello") :strip-prefix "hello") => (box "")) +(check ((box "hello") :strip-prefix "abc") => (box "hello")) +(check ((box "hello") :strip-prefix "helloo") => (box "hello")) +(check (((box "hello") :strip-prefix "he"):strip-prefix "ll") => (box "o")) + +(check-catch 'wrong-number-of-args ("hello" :strip-prefix "he")) +(check-catch 'syntax-error (123 :strip-prefix 1)) (check ((box '(1 2 3)) :apply 0) => 1) (check ((box '(1 2 3)) 0) => 1) -- Gitee