Something went wrong. Try again.
Jam Programming Language jamlang.org
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697// std.string byte-slice utilities.const { assert } = import("test");const { eq, startsWith, endsWith, find, contains, indexOfByte } = import("string");
tfn eqSelf() { var s: []u8 = "hello"; assert(eq(s, s) as i32, 1);}
tfn eqIdenticalLiterals() { var a: []u8 = "world"; var b: []u8 = "world"; assert(eq(a, b) as i32, 1);}
tfn eqDifferentLengths() { var a: []u8 = "abc"; var b: []u8 = "abcd"; assert(eq(a, b) as i32, 0);}
tfn eqDifferentBytes() { var a: []u8 = "abc"; var b: []u8 = "abd"; assert(eq(a, b) as i32, 0);}
tfn startsWithMatch() { assert(startsWith("hello world", "hello") as i32, 1);}
tfn startsWithMiss() { assert(startsWith("hello world", "world") as i32, 0);}
tfn startsWithEmptyPrefix() { assert(startsWith("hello", "") as i32, 1);}
tfn startsWithLongerPrefix() { assert(startsWith("ab", "abc") as i32, 0);}
tfn endsWithMatch() { assert(endsWith("hello world", "world") as i32, 1);}
tfn endsWithMiss() { assert(endsWith("hello world", "hello") as i32, 0);}
tfn endsWithEmpty() { assert(endsWith("foo", "") as i32, 1);}
tfn findMatch() { assert(find("hello world", "world"), 6);}
tfn findFirstOccurrence() { // Multiple matches return the lowest index. assert(find("aabaab", "ab"), 1);}
tfn findMiss() { assert(find("hello", "xyz"), -1);}
tfn findEmptyNeedle() { assert(find("hello", ""), 0);}
tfn findAtZero() { assert(find("abc", "abc"), 0);}
tfn containsTrue() { assert(contains("hello world", "lo wo") as i32, 1);}
tfn containsFalse() { assert(contains("hello", "zz") as i32, 0);}
tfn indexOfByteFound() { var s: []u8 = "hello"; var l: u8 = 108; // 'l' assert(indexOfByte(s, l), 2);}
tfn indexOfByteMissing() { var s: []u8 = "hello"; var z: u8 = 122; // 'z' assert(indexOfByte(s, z), -1);}