<commit_before># It's not real "perl"! It just looks like it.
test_post( "Hello, World", <<'CODE', <<'RESULT');
.sub "main"
    "hello"()
.end

.sub "hello"
    say "Hello, World"
.end
CODE
Hello, World
RESULT

test_post( "Hello, World (dynamic)", <<'CODE', <<'RESULT');
.sub "main"
    $P0 = find_sub_not_null "hello"
    $P0()
.end

.sub "hello"
    say "Hello, World"
.end
CODE
Hello, World
RESULT

test_post( "Hello, World (arg)", <<'CODE', <<'RESULT');
.sub "main"
    "hello"("Hello, World")
.end

.sub "hello"
    .param string greeting
    say greeting
.end
CODE
Hello, World
RESULT

test_post( "Multiple args", <<'CODE', <<'RESULT');
.sub "main"
    $P0 = new "String"
    $P0 = "Answer"
    "hello"($P0, "is", 42)
.end

.sub "hello"
    .param pmc answer
    .param string is
    .param int fortytwo
    print answer
    print " "
    print is
    print " "
    say fortytwo
.end
CODE
Answer is 42
RESULT

test_post( "Simple .return()", <<'CODE', <<'RESULT');
.sub "main"
    $S0 = answer()
    say $S0
.end

.sub "answer"
    .return( "Answer is 42" )
.end
CODE
Answer is 42
RESULT


test_post( ":slurpy", <<'CODE', <<'RESULT');
.sub "main"
    $P0 = new "String"
    $P0 = "Answer"
    "hello"($P0, " is ", 42)
.end

.sub "hello"
    .param pmc bits :slurpy

    $P0 = iter bits
  loop:
    unless $P0 goto done
    $S0 = shift $P0
    print $S0
    goto loop

  done:  
    say ""
.end
CODE
Answer is 42
RESULT



# vim: ft=perl<commit_msg>Add test for :optional<commit_after># It's not real "perl"! It just looks like it.
test_post( "Hello, World", <<'CODE', <<'RESULT');
.sub "main"
    "hello"()
.end

.sub "hello"
    say "Hello, World"
.end
CODE
Hello, World
RESULT

test_post( "Hello, World (dynamic)", <<'CODE', <<'RESULT');
.sub "main"
    $P0 = find_sub_not_null "hello"
    $P0()
.end

.sub "hello"
    say "Hello, World"
.end
CODE
Hello, World
RESULT

test_post( "Hello, World (arg)", <<'CODE', <<'RESULT');
.sub "main"
    "hello"("Hello, World")
.end

.sub "hello"
    .param string greeting
    say greeting
.end
CODE
Hello, World
RESULT

test_post( "Multiple args", <<'CODE', <<'RESULT');
.sub "main"
    $P0 = new "String"
    $P0 = "Answer"
    "hello"($P0, "is", 42)
.end

.sub "hello"
    .param pmc answer
    .param string is
    .param int fortytwo
    print answer
    print " "
    print is
    print " "
    say fortytwo
.end
CODE
Answer is 42
RESULT

test_post( "Simple .return()", <<'CODE', <<'RESULT');
.sub "main"
    $S0 = answer()
    say $S0
.end

.sub "answer"
    .return( "Answer is 42" )
.end
CODE
Answer is 42
RESULT


test_post( ":slurpy", <<'CODE', <<'RESULT');
.sub "main"
    $P0 = new "String"
    $P0 = "Answer"
    "hello"($P0, " is ", 42)
.end

.sub "hello"
    .param pmc bits :slurpy

    $P0 = iter bits
  loop:
    unless $P0 goto done
    $S0 = shift $P0
    print $S0
    goto loop

  done:  
    say ""
.end
CODE
Answer is 42
RESULT


test_post( ":optional", <<'CODE', <<'RESULT');
.sub "main"
    hello()
    hello("stranger")
.end

.sub "hello"
    .param string who     :optional
    .param int    has_who :opt_flag

    print "Hello, "
    if has_who goto has
    say "World"
    goto done
  has:
    say who

  done:

.end
CODE
Hello, World
Hello, stranger
RESULT



# vim: ft=perl
{'fraction_non_alphanumeric': 0.16917871424177175, 'fraction_numerical': 0.016610273761919408, 'mean_word_length': 2.720823798627002, 'pattern_counts': {'":': 3, '<': 55, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2043479', 'n_tokens_mistral': 1323, 'n_tokens_neox': 1261, 'n_words': 414}