forked from AssemblyScript/assemblyscript
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstring.ts
More file actions
33 lines (27 loc) · 890 Bytes
/
string.ts
File metadata and controls
33 lines (27 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// preliminary
var str: string = "hi, I'm a string";
// exactly once in static memory
assert(changetype<usize>(str) == changetype<usize>("hi, I'm a string"));
assert(str.length == 16);
assert(str.charCodeAt(0) == 0x68);
assert(str.startsWith("hi"));
assert(str.endsWith("string"));
assert(str.includes("I'm"));
assert(str.indexOf(",") == 2);
assert(str.indexOf("x") == -1);
export function getString(): string {
return str;
}
assert(parseInt("0") == 0);
assert(parseInt("1") == 1);
assert(parseInt("0b101") == 0b101);
assert(parseInt("0o707") == 0o707);
assert(parseInt("0xf0f") == 0xf0f);
assert(parseInt("0xF0F") == 0xf0f);
assert(parseInt("011") == 11); // not octal
assert(parseInt("0x1g") == 1); // not valid
assert(parseFloat("0") == 0);
assert(parseFloat("1") == 1);
assert(parseFloat("0.1") == 0.1);
assert(parseFloat(".25") == 0.25);
assert(parseFloat(".1foobar") == 0.1);