import HelderCore import Testing @Suite struct YAMLGrammarTests { @Test("keys, scalars, booleans, numbers and comments") func basics() { let text = "name: helder # app\nport: 8080\ndebug: true\nempty: ~\nurl: http://x.test:80\n\"quoted key\": 'v'" #expect(role("name", in: text, .yaml) == .keyword) #expect(role("# app", in: text, .yaml) == .comment) #expect(role("8080", in: text, .yaml) == .number) #expect(role("true", in: text, .yaml) == .keyword) #expect(role("~", in: text, .yaml) == .keyword) #expect(role("http://x.test:80", in: text, .yaml) == .plain) #expect(role("\"quoted key\"", in: text, .yaml) == .keyword) #expect(role("'v'", in: text, .yaml) == .string) } @Test("a block scalar runs while the lines stay indented") func blockScalar() { let text = "script: |\n echo: hi\n\n more\nnext: 1" #expect(role(" echo: hi", in: text, .yaml) == nil) #expect(role("echo: hi", in: text, .yaml) == .string) #expect(role("more", in: text, .yaml) == .string) #expect(role("next", in: text, .yaml) == .keyword) } @Test("lists, anchors, aliases and tags") func listsAndAnchors() { let text = "base: &base\n - item: !!str 1\nuse: *base" #expect(role("&base", in: text, .yaml) == .keyword) #expect(role("item", in: text, .yaml) == .keyword) #expect(role("!!str", in: text, .yaml) == .number) #expect(role("*base", in: text, .yaml) == .keyword) } @Test("flow collections split on commas") func flow() { let text = "tags: [a, 2, true]" #expect(role("2", in: text, .yaml) == .number) #expect(role("true", in: text, .yaml) == .keyword) } }