Skip to content

Commit

Permalink
Merge branch 'main' of github.com:roc-lang/unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton-4 committed Jan 24, 2025
2 parents 5d6d79d + 176382f commit 6d1eb60
Show file tree
Hide file tree
Showing 23 changed files with 6,688 additions and 6,678 deletions.
9 changes: 1 addition & 8 deletions .github/workflows/tests-nix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,4 @@ jobs:

# Run all tests
- name: Run all tests
run: nix develop -c sh -c 'export ROC=roc && ./ci/all_tests.sh'

- name: Run all tests and capture output to check for crash later
run: nix develop -c sh -c 'export ROC=roc && ./ci/all_tests.sh 2>&1 | tee all_tests_output.log'

# Workaround for https://github.com/roc-lang/roc/issues/6688
- name: Check if crash occurred
run: grep -qv "crashed" all_tests_output.log
run: nix develop -c sh -c 'export ROC=roc && ./ci/all_tests.sh'
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

# Ignore the example binaries
examples/nrOfCodePoints
examples/getVisualWidth
examples/splitGraphemes
examples/get-visual-width
examples/nr-of-code-points
examples/split-graphemes

# Ignore the generated files
generated-docs
Expand Down
25 changes: 25 additions & 0 deletions examples/get-visual-width.roc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
app [main!] {
pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.19.0/bi5zubJ-_Hva9vxxPq4kNx4WHX6oFs8OP6Ad0tCYlrY.tar.br",
unicode: "../package/main.roc", # use release URL (ends in tar.br) for local example, see github.com/roc/unicode/releases
}

import pf.Stdout
import unicode.CodePoint

word = "世界"

## Get the display width (in amount of characters) of a Str
get_visual_width : Str -> Result U32 CodePoint.Utf8ParseErr
get_visual_width = |str|
str
|> Str.to_utf8
|> CodePoint.parse_utf8
|> Result.map_ok(|lst| List.map(lst, CodePoint.visual_width))
|> Result.map_ok(List.sum)

main! = |_args|
when get_visual_width(word) is
Ok(width) -> Stdout.line!("\n\nThe word ${word} will be displayed with the width of ${Num.to_str(width)} characters on most UIs.\n\n")
Err(_) -> crash("ERROR: Unable to parse ${word}!")

expect (get_visual_width(word)) == Ok(4)
25 changes: 0 additions & 25 deletions examples/getVisualWidth.roc

This file was deleted.

22 changes: 22 additions & 0 deletions examples/nr-of-code-points.roc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
app [main!] {
pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.19.0/bi5zubJ-_Hva9vxxPq4kNx4WHX6oFs8OP6Ad0tCYlrY.tar.br",
unicode: "../package/main.roc", # use release URL (ends in tar.br) for local example, see github.com/roc/unicode/releases
}

import pf.Stdout
import unicode.CodePoint exposing [Utf8ParseErr]

## Get the number of code points for a given Str
nr_of_code_points : Str -> Result U64 Utf8ParseErr
nr_of_code_points = |str|
str |> Str.to_utf8 |> CodePoint.parse_utf8 |> Result.map_ok(List.len)

main! = |_args|
word = "ẇ͓̞͒͟͡ǫ̠̠̉̏͠͡ͅr̬̺͚̍͛̔͒͢d̠͎̗̳͇͆̋̊͂͐"

when nr_of_code_points(word) is
Ok(nr) ->
Stdout.line!("String \"${word}\" consists of ${Num.to_str(nr)} code points.")

Err(_) ->
Err(Exit(1, "Failed to parse string ${word} as Utf8."))
22 changes: 0 additions & 22 deletions examples/nrOfCodePoints.roc

This file was deleted.

19 changes: 19 additions & 0 deletions examples/split-graphemes.roc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
app [main!] {
pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.19.0/bi5zubJ-_Hva9vxxPq4kNx4WHX6oFs8OP6Ad0tCYlrY.tar.br",
unicode: "../package/main.roc", # use release URL (ends in tar.br) for local example, see github.com/roc/unicode/releases
}

import pf.Stdout
import unicode.Grapheme

string = "🇦🇺🦘🪃"

expect Grapheme.split(string) == Ok(["🇦🇺", "🦘", "🪃"])

main! = |_args|
string
|> Grapheme.split
|> Inspect.to_str
|> |splitted|
Stdout.line!("\n\nThe string \"${string}\" has following graphemes:")?
Stdout.line!(splitted)
19 changes: 0 additions & 19 deletions examples/splitGraphemes.roc

This file was deleted.

32 changes: 16 additions & 16 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6d1eb60

Please sign in to comment.