···11+import { Ok, Error } from "./gleam.mjs";
22+33+export function strip_prefix(string, prefix) {
44+ if (string.startsWith(prefix)) {
55+ return new Ok(string.slice(prefix.length));
66+ } else {
77+ return new Error(undefined);
88+ }
99+}
+44
test/pearl_test.gleam
···9595 ])
9696}
97979898+pub fn triple_quoted_string_test() {
9999+ let src =
100100+ "
101101+\"\"\"
102102+\t Hello, this is triple-quoted!
103103+\t This line starts with a space
104104+\t Quotes are allowed: \"\", even three: \"\"\"
105105+\t \"\"\"
106106+"
107107+108108+ assert_tokens(src, [
109109+ token.TripleQuotedString(
110110+ beginning_whitespace: " \n",
111111+ lines: [
112112+ "Hello, this is triple-quoted!",
113113+ " This line starts with a space",
114114+ "Quotes are allowed: \"\", even three: \"\"\"",
115115+ ],
116116+ end_indentation: "\t ",
117117+ ),
118118+ ])
119119+}
120120+98121pub fn unknown_character_test() {
99122 let src = "a&b"
100123 assert_errors(src, [pearl.UnknownCharacter("&")])
···212235 let src = "1.2e-"
213236 assert_errors(src, [pearl.ExpectedExponent])
214237}
238238+239239+pub fn missing_whitespace_after_triple_quote() {
240240+ let src =
241241+ "\"\"\"Hello
242242+\"\"\""
243243+ assert_errors(src, [pearl.ExpectedWhitespaceAfterTripleQuote])
244244+}
245245+246246+pub fn invalid_triple_quoted_string_indentation() {
247247+ let src =
248248+ "\"\"\"
249249+ Hello
250250+ world
251251+ \"\"\""
252252+ assert_errors(src, [
253253+ pearl.InvalidTripleQuotedStringIndentation(
254254+ expected_indentation: " ",
255255+ line: " Hello",
256256+ ),
257257+ ])
258258+}
+6
test/tokens.txt
···1414~/I need "quotes"/ ~<This is also possible> ~b"Bit array"
1515Variable Something_else@5
16161717+"""
1818+ Triple quoted!
1919+ This line is indented, and has quotes: ""
2020+ Three quotes allowed here: """ and here: """
2121+ """
2222+1723after
1824begin
1925case