| 1 | # spec/ysh-methods |
| 2 | |
| 3 | ## our_shell: ysh |
| 4 | ## oils_failures_allowed: 0 |
| 5 | |
| 6 | #### Str->startswith |
| 7 | = "abc"->startswith("") |
| 8 | = "abc"->startswith("a") |
| 9 | = "abc"->startswith("z") |
| 10 | ## status: 0 |
| 11 | ## STDOUT: |
| 12 | (Bool) True |
| 13 | (Bool) True |
| 14 | (Bool) False |
| 15 | ## END |
| 16 | |
| 17 | #### Str->startswith, no args |
| 18 | = "abc"->startswith() |
| 19 | ## status: 3 |
| 20 | |
| 21 | #### Str->startswith, too many args |
| 22 | = "abc"->startswith("extra", "arg") |
| 23 | ## status: 3 |
| 24 | |
| 25 | #### Missing method (Str->doesNotExist()) |
| 26 | = "abc"->doesNotExist() |
| 27 | ## status: 3 |
| 28 | |
| 29 | #### Dict->keys() |
| 30 | var en2fr = {} |
| 31 | setvar en2fr["hello"] = "bonjour" |
| 32 | setvar en2fr["friend"] = "ami" |
| 33 | setvar en2fr["cat"] = "chat" |
| 34 | = en2fr->keys() |
| 35 | ## status: 0 |
| 36 | ## STDOUT: |
| 37 | (List) ['hello', 'friend', 'cat'] |
| 38 | ## END |
| 39 | |
| 40 | #### Seperation of -> attr and () calling |
| 41 | const check = "abc"->startswith |
| 42 | = check("a") |
| 43 | ## status: 0 |
| 44 | ## STDOUT: |
| 45 | (Bool) True |
| 46 | ## END |
| 47 | |
| 48 | #### Bound methods, receiver value/reference semantics |
| 49 | var is_a_ref = { "foo": "bar" } |
| 50 | const f = is_a_ref->keys |
| 51 | = f() |
| 52 | setvar is_a_ref["baz"] = 42 |
| 53 | = f() |
| 54 | |
| 55 | var is_a_val = "abc" |
| 56 | const g = is_a_val->startswith |
| 57 | = g("a") |
| 58 | setvar is_a_val = "xyz" |
| 59 | = g("a") |
| 60 | ## status: 0 |
| 61 | ## STDOUT: |
| 62 | (List) ['foo'] |
| 63 | (List) ['foo', 'baz'] |
| 64 | (Bool) True |
| 65 | (Bool) True |
| 66 | ## END |