<commit_before>import XCTest
import Song

class LiteralParserTests: XCTestCase {

    func test_bools() {
        "Yes".makes(.yes)
        "No".makes(.no)
        " Yes ".makes(.yes)
    }

    func test_ints() {
        "99".makes(.int(99))
        "+99".makes(.int(99))
        "-21".makes(.call("-", [.int(21)]))
        "0".makes(.int(0))
        "-0".makes(.call("-", [.int(0)]))
        " 99 ".makes(.int(99))

        "9d".fails()
    }

    func test_floats() {
        "0.1".makes(.float(0.1))
        "+0.1".makes(.float(0.1))
        "-9.1".makes(.call("-", [.float(9.1)]))
        "0.001".makes(.float(0.001))
        " 0.001 ".makes(.float(0.001))

        ".1".fails()
    }

    func test_chars() {
        "'A'".makes(.char("A"))
        "'é'".makes(.char("é"))
        "'😀'".makes(.char("😀"))
        "' '".makes(.char(" "))
        "'\\''".makes(.char("'"))
        "'\"'".makes(.char("\""))
        "'\\\\'".makes(.char("\\"))
        "'\n'".makes(.char("\n"))
        "'AB'".fails()
        "'''".fails()
    }

    func test_strings() {
        "\"\"".makes(.string(""))
        "\"'\"".makes(.string("'"))
        "\"hello world\"".makes(.string("hello world"))
"""
\"hello
world\"
""".makes(.string("hello\nworld"))
        "\"café\"".makes(.string("café"))
        "\"😀\"".makes(.string("😀"))
        "\"Hi, I said\"".makes(.string("Hi, I said"))
        "\"\\\"Hi,\\\" I said\"".makes(.string("\"Hi,\" I said"))
        "\"\n\"".makes(.string("\n"))
        "\"a\\\\backslash\"".makes(.string("a\\backslash"))
        " \"hello world\" ".makes(.string("hello world"))
    }

    func test_lists() {
        "[]".makes(.list([]))
        " [] ".makes(.list([]))
        "[1,No]".makes(.list([.int(1), .no]))
        "[ 1 , Yes , \"hi\" ]".makes(.list([.int(1), .yes, .string("hi")]))
        "[[1,2],[No,4], [], \"hi\"]".makes(.list([
            .list([.int(1), .int(2)]),
            .list([.no, .int(4)]),
            .list([]),
            .string("hi")
            ]))
        """
[
  1 ,

  No
]
""".makes(.list([.int(1), .no]))
    }

    func test_cons() {
        "[x|xs]".makes(.cons([.name("x")], .name("xs")))
        "[x,y|xs]".makes(.cons([.name("x"), .name("y")], .name("xs")))
        "[ 1 , x | xs ]".makes(.cons([.int(1), .name("x")], .name("xs")))
        "[Yes|2]".makes(.cons([.yes], .int(2)))
        "[ f(x) | g(x) ]".makes(.cons([.call("f", [.name("x")])],
                                      .call("g", [.name("x")])))<commit_msg>Tests.<commit_after>import XCTest
import Song

class LiteralParserTests: XCTestCase {

    func test_bools() {
        "Yes".makes(.yes)
        "No".makes(.no)
        " Yes ".makes(.yes)
    }

    func test_ints() {
        "99".makes(.int(99))
        "+99".makes(.int(99))
        "-21".makes(.call("-", [.int(21)]))
        "0".makes(.int(0))
        "-0".makes(.call("-", [.int(0)]))
        " 99 ".makes(.int(99))

        "9d".fails()
    }

    func test_floats() {
        "0.1".makes(.float(0.1))
        "+0.1".makes(.float(0.1))
        "-9.1".makes(.call("-", [.float(9.1)]))
        "0.001".makes(.float(0.001))
        " 0.001 ".makes(.float(0.001))

        ".1".fails()
    }

    func test_chars() {
        "'A'".makes(.char("A"))
        "'é'".makes(.char("é"))
        "'😀'".makes(.char("😀"))
        "' '".makes(.char(" "))
        "'\\''".makes(.char("'"))
        "'\"'".makes(.char("\""))
        "'\\\\'".makes(.char("\\"))
        "'\n'".makes(.char("\n"))
        "'\r'".makes(.char("\r"))
        "'\t'".makes(.char("\t"))
        "'AB'".fails()
        "'''".fails()
    }

    func test_strings() {
        "\"\"".makes(.string(""))
        "\"'\"".makes(.string("'"))
        "\"hello world\"".makes(.string("hello world"))
"""
\"hello
world\"
""".makes(.string("hello\nworld"))
        "\"café\"".makes(.string("café"))
        "\"😀\"".makes(.string("😀"))
        "\"Hi, I said\"".makes(.string("Hi, I said"))
        "\"\\\"Hi,\\\" I said\"".makes(.string("\"Hi,\" I said"))
        "\"\n\"".makes(.string("\n"))
        "\"\r\"".makes(.string("\r"))
        "\"\t\"".makes(.string("\t"))
        "\"a\\\\backslash\"".makes(.string("a\\backslash"))
        " \"hello world\" ".makes(.string("hello world"))
    }

    func test_lists() {
        "[]".makes(.list([]))
        " [] ".makes(.list([]))
        "[1,No]".makes(.list([.int(1), .no]))
        "[ 1 , Yes , \"hi\" ]".makes(.list([.int(1), .yes, .string("hi")]))
        "[[1,2],[No,4], [], \"hi\"]".makes(.list([
            .list([.int(1), .int(2)]),
            .list([.no, .int(4)]),
            .list([]),
            .string("hi")
            ]))
        """
[
  1 ,

  No
]
""".makes(.list([.int(1), .no]))
    }

    func test_cons() {
        "[x|xs]".makes(.cons([.name("x")], .name("xs")))
        "[x,y|xs]".makes(.cons([.name("x"), .name("y")], .name("xs")))
        "[ 1 , x | xs ]".makes(.cons([.int(1), .name("x")], .name("xs")))
        "[Yes|2]".makes(.cons([.yes], .int(2)))
        "[ f(x) | g(x) ]".makes(.cons([.call("f", [.name("x")])],
                                      .call("g", [.name("x")])))
{'fraction_non_alphanumeric': 0.32875906684963735, 'fraction_numerical': 0.02587727896490884, 'mean_word_length': 1.7668112798264641, 'pattern_counts': {'":': 0, '<': 3, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '126427', 'n_tokens_mistral': 2173, 'n_tokens_neox': 1912, 'n_words': 243}