repro_double_equals.rs
1 use korni::{parse, Entry}; 2 3 #[test] 4 fn test_double_equals_should_fail() { 5 let input = "KEY==value"; 6 let entries = parse(input); 7 8 // CURRENT BEHAVIOR: This is expected to fail with "Unexpected entry type" if the parser 9 // currently parses this as KEY = "=value". If it already fails, then great. 10 // The user wants clear error for this. 11 match entries.first().unwrap() { 12 Entry::Error(e) => { 13 let msg = e.to_string(); 14 println!("Got expected error: {}", msg); 15 assert!(msg.contains("Double equals sign"), "Error message should mention double equals"); 16 }, 17 Entry::Pair(pair) => panic!("Should result in error, but got Pair: {:?}={:?}", pair.key, pair.value), 18 _ => panic!("Unexpected entry type"), 19 } 20 } 21 22 #[test] 23 fn test_multiple_equals_in_value_ok() { 24 let input = "KEY=value=with=equals"; 25 let entries = parse(input); 26 27 match entries.first().unwrap() { 28 Entry::Pair(pair) => { 29 assert_eq!(pair.key, "KEY"); 30 assert_eq!(pair.value, "value=with=equals"); 31 }, 32 _ => panic!("Should be valid pair: {:?}", entries.first()), 33 } 34 } 35 36 #[test] 37 fn test_multiple_equals_quoted_ok() { 38 // Spec: Quoted values can contain equals 39 let input = "KEY=\"=value\""; 40 let entries = parse(input); 41 42 match entries.first().unwrap() { 43 Entry::Pair(pair) => { 44 assert_eq!(pair.key, "KEY"); 45 assert_eq!(pair.value, "=value"); 46 }, 47 _ => panic!("Should be valid pair"), 48 } 49 } 50 51 #[test] 52 fn test_multiple_equals_quoted_single_ok() { 53 let input = "KEY='=value'"; 54 let entries = parse(input); 55 56 match entries.first().unwrap() { 57 Entry::Pair(pair) => { 58 assert_eq!(pair.key, "KEY"); 59 assert_eq!(pair.value, "=value"); 60 }, 61 _ => panic!("Should be valid pair"), 62 } 63 }