Skip to content

Commit

Permalink
!273 rich-char%make-string in (liii lang)
Browse files Browse the repository at this point in the history
  • Loading branch information
da-liii committed Mar 3, 2025
1 parent c1fa2be commit 8bc35fb
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 5 deletions.
54 changes: 50 additions & 4 deletions GoldfishLang.tmu
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<TMU|<tuple|1.1.0|2025.0.5>>
<TMU|<tuple|1.1.0|2025.0.4>>

<style|<tuple|book|goldfish|literate|reduced-margins|python|padded-paragraphs|chinese>>

Expand Down Expand Up @@ -1519,9 +1519,9 @@

<paragraph|rich-char%numeric?>

<paragraph|rich-char%upper-case?>
<paragraph|rich-char%upper?>

<paragraph|rich-char%lower-case?>
<paragraph|rich-char%lower?>

<paragraph|rich-char%digit?>

Expand Down Expand Up @@ -2021,6 +2021,50 @@
\;
</goldfish-chunk>

<paragraph|rich-string%make-string><typehint|() =\<gtr\> rich-string>

<\goldfish-chunk|goldfish/liii/lang.scm|true|true>
(define (%make-string)

\ \ (rich-string (utf8-\>string (%to-bytevector))))

\;
</goldfish-chunk>

<subparagraph|测试>

不可见的ASCII字符

<\goldfish-chunk|tests/goldfish/liii/lang-test.scm|true|true>
(check ($ #\\space :make-string) =\<gtr\> " ")

(check ($ #\\return :make-string) =\<gtr\> (string #\\return))

\;
</goldfish-chunk>

普通的字母

<\goldfish-chunk|tests/goldfish/liii/lang-test.scm|true|true>
(check ($ #\\a :make-string) =\<gtr\> "a")

(check ($ #\\A :make-string) =\<gtr\> "A")

\;
</goldfish-chunk>

ASCII范围外的字符:希腊字母、中文、表情符:

<\goldfish-chunk|tests/goldfish/liii/lang-test.scm|true|true>
(check ((rich-char #xA3) :make-string) =\<gtr\> "£")

(check ((rich-char #x4E2D) :make-string) =\<gtr\> "<code|中>")

(check ((rich-char #x1F600) :make-string) =\<gtr\> "<code|😀>")

\;
</goldfish-chunk>

<subsection|结尾>

\;
Expand Down Expand Up @@ -2168,7 +2212,7 @@

\ \ \ \ \ \ \ \ ((and (case-class? v) (v :is-instance-of 'rich-char))

\ \ \ \ \ \ \ \ \ ($ (v :to-string) :strip-prefix "#\\\\"))
\ \ \ \ \ \ \ \ \ (v :make-string))

\ \ \ \ \ \ \ \ (else (type-error "Expected types are char, rich-char, number, symbol or string"))))

Expand All @@ -2188,6 +2232,8 @@

(check (rich-string :value-of (rich-char #x4E2D)) =\<gtr\> "中")

(check (rich-string :value-of #\\ ) =\<gtr\> " ")

\;
</goldfish-chunk>

Expand Down
5 changes: 4 additions & 1 deletion goldfish/liii/lang.scm
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,9 @@
(object->string (integer->char code-point))
(string-append "#\\" (utf8->string (%to-bytevector)))))

(define (%make-string)
(rich-string (utf8->string (%to-bytevector))))

)

(define make-rich-char rich-char)
Expand Down Expand Up @@ -403,7 +406,7 @@
((symbol? v) (rich-string (symbol->string v)))
((string? v) (rich-string v))
((and (case-class? v) (v :is-instance-of 'rich-char))
($ (v :to-string) :strip-prefix "#\\"))
(v :make-string))
(else (type-error "Expected types are char, rich-char, number, symbol or string"))))

(define (%get) data)
Expand Down
11 changes: 11 additions & 0 deletions tests/goldfish/liii/lang-test.scm
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,23 @@

(check ((rich-char #x1F600) :to-string) => "#\\😀")

(check ($ #\space :make-string) => " ")
(check ($ #\return :make-string) => (string #\return))

(check ($ #\a :make-string) => "a")
(check ($ #\A :make-string) => "A")

(check ((rich-char #xA3) :make-string) => "£")
(check ((rich-char #x4E2D) :make-string) => "")
(check ((rich-char #x1F600) :make-string) => "😀")

(check (rich-string :value-of #\a) => "a")
(check (rich-string :value-of 'a) => "a")
(check (rich-string :value-of 123) => "123")
(check (rich-string :value-of 1.0) => "1.0")
(check (rich-string :value-of "abc") => "abc")
(check (rich-string :value-of (rich-char #x4E2D)) => "")
(check (rich-string :value-of #\ ) => " ")

(check ($ "abc" :get) => "abc")
(check ($ "" :get) => "")
Expand Down

0 comments on commit 8bc35fb

Please sign in to comment.