diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 833e7dd..3ed14b0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ on: branches: [main] env: - RUST_TOOLCHAIN: "1.89.0" + RUST_TOOLCHAIN: "1.97.0" jobs: test: @@ -27,6 +27,8 @@ jobs: key: ${{ runner.os }}-almide-${{ env.RUST_TOOLCHAIN }}-${{ hashFiles('almide.lock') }} restore-keys: ${{ runner.os }}-almide-${{ env.RUST_TOOLCHAIN }}- - name: Install Almide - run: cargo install --git https://github.com/almide/almide.git --branch develop + run: | + curl -fsSL "https://github.com/almide/almide/releases/download/v0.69.0/almide-linux-x86_64.tar.gz" -o almide.tar.gz + tar xzf almide.tar.gz --strip-components=1 && sudo mv almide /usr/local/bin/ && almide --version - name: Run tests run: almide test diff --git a/spec/csv_test.almd b/spec/csv_test.almd index b1671f3..fc9e86d 100644 --- a/spec/csv_test.almd +++ b/spec/csv_test.almd @@ -1,5 +1,5 @@ import self as csv -import json + fn unwrap(r: Result[Value, String]) -> Value = match r { ok(v) => v, @@ -105,15 +105,15 @@ test "parse_records empty input" { // ═══════════════════════════════════════════════════════ test "stringify simple" { let v = value.array([ - value.array([value.str("a"), value.str("b")]), - value.array([value.str("1"), value.str("2")]) + value.array([value.string("a"), value.string("b")]), + value.array([value.string("1"), value.string("2")]) ]); assert_eq(csv.stringify(v), "a,b\n1,2") } test "stringify escapes comma" { let v = value.array([ - value.array([value.str("hello, world"), value.str("ok")]) + value.array([value.string("hello, world"), value.string("ok")]) ]); let result = csv.stringify(v); assert(string.contains(result, '"hello, world"')) @@ -121,7 +121,7 @@ test "stringify escapes comma" { test "stringify escapes quotes" { let v = value.array([ - value.array([value.str('say "hi"'), value.str("ok")]) + value.array([value.string('say "hi"'), value.string("ok")]) ]); let result = csv.stringify(v); assert(string.contains(result, '"say ""hi"""')) @@ -132,8 +132,8 @@ test "stringify escapes quotes" { // ═══════════════════════════════════════════════════════ test "stringify_records" { let v = value.array([ - value.object([("name", value.str("Alice")), ("age", value.str("30"))]), - value.object([("name", value.str("Bob")), ("age", value.str("25"))]) + value.object([("name", value.string("Alice")), ("age", value.string("30"))]), + value.object([("name", value.string("Bob")), ("age", value.string("25"))]) ]); let result = csv.stringify_records(v); assert(string.contains(result, "name,age")); diff --git a/src/mod.almd b/src/mod.almd index bef1c4e..d47fef0 100644 --- a/src/mod.almd +++ b/src/mod.almd @@ -13,7 +13,7 @@ import json effect fn parse(text: String) -> Result[Value, String] = { let rows = parse_rows(text) - ok(value.array(rows |> list.map((row) => value.array(row |> list.map((cell) => value.str(cell)))))) + ok(value.array(rows |> list.map((row) => value.array(row |> list.map((cell) => value.string(cell)))))) } fn stringify(v: Value) -> String = { @@ -21,7 +21,7 @@ fn stringify(v: Value) -> String = { rows |> list.map((row) => { let cells = value.as_array(row) ?? [] - cells |> list.map((cell) => escape_cell(value.as_string(cell) ?? value.stringify(cell))) |> list.join(",") + cells |> list.map((cell) => escape_cell(value.as_string(cell) ?? json.stringify(cell))) |> list.join(",") }) |> list.join("\n") } @@ -36,7 +36,7 @@ effect fn parse_records(text: String) -> Result[Value, String] = { |> list.enumerate |> list.map((entry) => { let (i, key) = entry - (key, value.str(list.get_or(row, i, ""))) + (key, value.string((list.get(row, i) ?? ""))) }) value.object(pairs) }) @@ -48,7 +48,7 @@ fn stringify_records(v: Value) -> String = { if list.is_empty(rows) then "" else { let first = list.get(rows, 0) ?? value.object([]) - let header = json.keys(first) + let header = list.map(value.as_object(first) ?? [], (kv) => kv.0) let header_line = header |> list.map((h) => escape_cell(h)) |> list.join(",") let data_lines = rows |> list.map((row) => { header |> list.map((h) => escape_cell(value.as_string(value.get(row, h) ?? value.null()) ?? "")) |> list.join(",")