81 lines
2.2 KiB
EmacsLisp
81 lines
2.2 KiB
EmacsLisp
// test_codegen_js.el - basic tests for JS codegen features.
|
|
//
|
|
// These tests verify that core El language features produce correct values
|
|
// when compiled and executed via the C backend. They serve as a
|
|
// regression baseline for the codegen pipeline.
|
|
|
|
test "arithmetic" {
|
|
let x: Int = 2 + 3
|
|
assert x == 5, "addition"
|
|
let y: Int = 10 - 4
|
|
assert y == 6, "subtraction"
|
|
let z: Int = 3 * 4
|
|
assert z == 12, "multiplication"
|
|
let w: Int = 15 / 3
|
|
assert w == 5, "division"
|
|
}
|
|
|
|
test "string-concat" {
|
|
let a: String = "hello"
|
|
let b: String = " world"
|
|
let c: String = a + b
|
|
assert c == "hello world", "string concatenation"
|
|
}
|
|
|
|
test "str-len" {
|
|
let n: Int = str_len("hello")
|
|
assert n == 5, "str_len hello"
|
|
let m: Int = str_len("")
|
|
assert m == 0, "str_len empty"
|
|
}
|
|
|
|
test "bool-logic" {
|
|
let t = true
|
|
let f = false
|
|
assert t, "true is truthy"
|
|
assert !f, "false negated is truthy"
|
|
assert t && !f, "true and not false"
|
|
assert t || f, "true or false"
|
|
}
|
|
|
|
test "list-operations" {
|
|
let lst: [Int] = native_list_empty()
|
|
let lst = native_list_append(lst, 10)
|
|
let lst = native_list_append(lst, 20)
|
|
let lst = native_list_append(lst, 30)
|
|
let n: Int = native_list_len(lst)
|
|
assert n == 3, "list length 3"
|
|
let v0: Int = native_list_get(lst, 0)
|
|
let v1: Int = native_list_get(lst, 1)
|
|
let v2: Int = native_list_get(lst, 2)
|
|
assert v0 == 10, "first element"
|
|
assert v1 == 20, "second element"
|
|
assert v2 == 30, "third element"
|
|
}
|
|
|
|
test "str-slice" {
|
|
let s: String = str_slice("hello world", 6, 11)
|
|
assert s == "world", "slice from 6 to 11"
|
|
}
|
|
|
|
test "str-contains" {
|
|
assert str_contains("hello world", "world"), "contains world"
|
|
assert !str_contains("hello world", "xyz"), "does not contain xyz"
|
|
}
|
|
|
|
test "int-to-str" {
|
|
let s: String = int_to_str(42)
|
|
assert s == "42", "int to string"
|
|
}
|
|
|
|
test "str-to-int" {
|
|
let n: Int = str_to_int("123")
|
|
assert n == 123, "string to int"
|
|
}
|
|
|
|
test "str-starts-ends" {
|
|
assert str_starts_with("hello world", "hello"), "starts with hello"
|
|
assert str_ends_with("hello world", "world"), "ends with world"
|
|
assert !str_starts_with("hello world", "world"), "does not start with world"
|
|
}
|