module scheme import arena import reader fn test_case_empty_raw_input_matches_repeated_and_dotted_patterns_like_wrapped_input() { for source in ['(x ...)', '((x ...) ...)', '(_ ...)', '(x ... . tail)', '(x ... . ())', '(x ... . _)'] { matcher := empty_case_spec(source) mut raw := SyntaxCaseCaptures{ pattern: matcher.pattern } assert matcher.matches_value(nil_value(), mut raw) or { panic(err) }, source mut wrapped := SyntaxCaseCaptures{ pattern: matcher.pattern } assert matcher.matches_value(empty_case_wrapped(), mut wrapped) or { panic(err) }, source for variable, spec in matcher.pattern.variables { if spec.depth > 0 { assert raw.coordinates.items[syntax_capture_key(variable, 0)] == 0 assert wrapped.coordinates.items[syntax_capture_key(variable, 0)] == 0 } else { assert raw.value(variable, []) or { panic(err) }.tag == .nil assert syntax_to_datum(wrapped.value(variable, []) or { panic(err) }) or { panic(err) }.tag == .nil } } } for source in ['(first x ...)', '(x ... last)', '(x)', '#(x ...)', '(x ... . 42)'] { matcher := empty_case_spec(source) mut frame := SyntaxCaseCaptures{ pattern: matcher.pattern } assert !(matcher.matches_value(nil_value(), mut frame) or { panic(err) }), source } } fn test_case_empty_zero_variable_predicate_retains_no_temporary_storage() { matcher := empty_case_spec('(_ ...)') mut captures := SyntaxCaseCaptures{ pattern: matcher.pattern } mut region := arena.new(chunk_size: 1048576) region.push() assert matcher.matches_value(nil_value(), mut captures) or { panic(err) } assert captures.coordinates.items.len == 0 && captures.coordinates.paths.len == 0 && isnil(captures.values) assert region.used() == 0 region.pop() region.free() } fn empty_case_spec(source string) SyntaxCaseMatcher { code := &Code{ doc: reader.read_all(source) or { panic(err) } } mut builder := Builder{ code: code, function: &Function{ code: code } } tree, roots := builder.freeze_syntax(code.doc.forms) or { panic(err) } pattern := tree.compile_case_pattern(roots[0], map[i32]SyntaxBinding{}) or { panic(err) } return SyntaxCaseMatcher{ tree: tree, pattern: &pattern } } fn empty_case_wrapped() Value { tree := &SyntaxTree{ nodes: [SyntaxTreeNode{ kind: .empty_list }] } return wrapped_syntax(&SyntaxObjectData{ tree: tree }, 0) or { panic(err) } }