// Ported from: https://github.com/mysticatea/regexpp/blob/master/test/fixtures/visitor/full.json // // Copyright (C) 2020 Quentin M. Kniep // Distributed under terms of the MIT license. extern crate js_regex; use js_regex::{EcmaRegexValidator, EcmaVersion}; #[test] fn basic_valid() { let mut validator = EcmaRegexValidator::new(EcmaVersion::ES2018); assert_eq!(validator.validate_pattern("foo", false), Ok(())); assert_eq!(validator.validate_pattern("foo|bar", false), Ok(())); assert_eq!(validator.validate_pattern("||||", false), Ok(())); assert_eq!(validator.validate_pattern("^|$|\\b|\\B", false), Ok(())); assert_eq!(validator.validate_pattern("(?=)", false), Ok(())); assert_eq!(validator.validate_pattern("(?=foo)", false), Ok(())); assert_eq!(validator.validate_pattern("(?!)", false), Ok(())); assert_eq!(validator.validate_pattern("(?!foo)", false), Ok(())); assert_eq!(validator.validate_pattern("(?=a)*", false), Ok(())); assert_eq!(validator.validate_pattern("(?=a)+", false), Ok(())); assert_eq!(validator.validate_pattern("(?=a)?", false), Ok(())); assert_eq!(validator.validate_pattern("(?=a){", false), Ok(())); assert_eq!(validator.validate_pattern("(?=a){}", false), Ok(())); assert_eq!(validator.validate_pattern("(?=a){a}", false), Ok(())); assert_eq!(validator.validate_pattern("(?=a){1}", false), Ok(())); assert_eq!(validator.validate_pattern("(?=a){1,}", false), Ok(())); assert_eq!(validator.validate_pattern("(?=a){1,2}", false), Ok(())); assert_eq!(validator.validate_pattern("a*", false), Ok(())); assert_eq!(validator.validate_pattern("a+", false), Ok(())); assert_eq!(validator.validate_pattern("a?", false), Ok(())); assert_eq!(validator.validate_pattern("a{", false), Ok(())); assert_eq!(validator.validate_pattern("a{}", false), Ok(())); assert_eq!(validator.validate_pattern("a{a}", false), Ok(())); assert_eq!(validator.validate_pattern("a{1}", false), Ok(())); assert_eq!(validator.validate_pattern("a{1", false), Ok(())); assert_eq!(validator.validate_pattern("a{1,}", false), Ok(())); assert_eq!(validator.validate_pattern("a{1,", false), Ok(())); assert_eq!(validator.validate_pattern("a{1,2}", false), Ok(())); assert_eq!(validator.validate_pattern("a{1,2", false), Ok(())); assert_eq!(validator.validate_pattern("a{2,1", false), Ok(())); assert_eq!(validator.validate_pattern("a*?", false), Ok(())); assert_eq!(validator.validate_pattern("a+?", false), Ok(())); assert_eq!(validator.validate_pattern("a??", false), Ok(())); assert_eq!(validator.validate_pattern("a{?", false), Ok(())); assert_eq!(validator.validate_pattern("a{}?", false), Ok(())); assert_eq!(validator.validate_pattern("a{a}?", false), Ok(())); assert_eq!(validator.validate_pattern("a{1}?", false), Ok(())); assert_eq!(validator.validate_pattern("a{1?", false), Ok(())); assert_eq!(validator.validate_pattern("a{1,}?", false), Ok(())); assert_eq!(validator.validate_pattern("a{1,?", false), Ok(())); assert_eq!(validator.validate_pattern("a{1,2}?", false), Ok(())); assert_eq!(validator.validate_pattern("a{1,2?", false), Ok(())); assert_eq!(validator.validate_pattern("a{2,1?", false), Ok(())); assert_eq!(validator.validate_pattern("👍🚀❇️", false), Ok(())); assert_eq!(validator.validate_pattern("^", false), Ok(())); assert_eq!(validator.validate_pattern("$", false), Ok(())); assert_eq!(validator.validate_pattern(".", false), Ok(())); assert_eq!(validator.validate_pattern("]", false), Ok(())); assert_eq!(validator.validate_pattern("{", false), Ok(())); assert_eq!(validator.validate_pattern("}", false), Ok(())); assert_eq!(validator.validate_pattern("|", false), Ok(())); assert_eq!(validator.validate_pattern("${1,2", false), Ok(())); assert_eq!(validator.validate_pattern("\\1", false), Ok(())); assert_eq!(validator.validate_pattern("(a)\\1", false), Ok(())); assert_eq!(validator.validate_pattern("\\1(a)", false), Ok(())); assert_eq!(validator.validate_pattern("(?:a)\\1", false), Ok(())); assert_eq!(validator.validate_pattern("(a)\\2", false), Ok(())); assert_eq!(validator.validate_pattern("(?:a)\\2", false), Ok(())); assert_eq!(validator.validate_pattern("(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)\\10", false), Ok(())); assert_eq!(validator.validate_pattern("(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)\\11", false), Ok(())); assert_eq!(validator.validate_pattern("(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)\\11", false), Ok(())); assert_eq!(validator.validate_pattern("(?:a)", false), Ok(())); assert_eq!(validator.validate_pattern("\\d", false), Ok(())); assert_eq!(validator.validate_pattern("\\D", false), Ok(())); assert_eq!(validator.validate_pattern("\\s", false), Ok(())); assert_eq!(validator.validate_pattern("\\S", false), Ok(())); assert_eq!(validator.validate_pattern("\\w", false), Ok(())); assert_eq!(validator.validate_pattern("\\W", false), Ok(())); assert_eq!(validator.validate_pattern("\\f", false), Ok(())); assert_eq!(validator.validate_pattern("\\n", false), Ok(())); assert_eq!(validator.validate_pattern("\\r", false), Ok(())); assert_eq!(validator.validate_pattern("\\t", false), Ok(())); assert_eq!(validator.validate_pattern("\\v", false), Ok(())); assert_eq!(validator.validate_pattern("\\cA", false), Ok(())); assert_eq!(validator.validate_pattern("\\cz", false), Ok(())); assert_eq!(validator.validate_pattern("\\c1", false), Ok(())); assert_eq!(validator.validate_pattern("\\c", false), Ok(())); assert_eq!(validator.validate_pattern("\\0", false), Ok(())); assert_eq!(validator.validate_pattern("\\u", false), Ok(())); assert_eq!(validator.validate_pattern("\\u1", false), Ok(())); assert_eq!(validator.validate_pattern("\\u12", false), Ok(())); assert_eq!(validator.validate_pattern("\\u123", false), Ok(())); assert_eq!(validator.validate_pattern("\\u1234", false), Ok(())); assert_eq!(validator.validate_pattern("\\u12345", false), Ok(())); assert_eq!(validator.validate_pattern("\\u{", false), Ok(())); assert_eq!(validator.validate_pattern("\\u{z", false), Ok(())); assert_eq!(validator.validate_pattern("\\u{a}", false), Ok(())); assert_eq!(validator.validate_pattern("\\u{20", false), Ok(())); assert_eq!(validator.validate_pattern("\\u{20}", false), Ok(())); assert_eq!(validator.validate_pattern("\\u{10FFFF}", false), Ok(())); assert_eq!(validator.validate_pattern("\\u{110000}", false), Ok(())); assert_eq!(validator.validate_pattern("\\u{00000001}", false), Ok(())); assert_eq!(validator.validate_pattern("\\377", false), Ok(())); assert_eq!(validator.validate_pattern("\\400", false), Ok(())); assert_eq!(validator.validate_pattern("\\^", false), Ok(())); assert_eq!(validator.validate_pattern("\\$", false), Ok(())); assert_eq!(validator.validate_pattern("\\.", false), Ok(())); assert_eq!(validator.validate_pattern("\\+", false), Ok(())); assert_eq!(validator.validate_pattern("\\?", false), Ok(())); assert_eq!(validator.validate_pattern("\\(", false), Ok(())); assert_eq!(validator.validate_pattern("\\)", false), Ok(())); assert_eq!(validator.validate_pattern("\\[", false), Ok(())); assert_eq!(validator.validate_pattern("\\]", false), Ok(())); assert_eq!(validator.validate_pattern("\\{", false), Ok(())); assert_eq!(validator.validate_pattern("\\}", false), Ok(())); assert_eq!(validator.validate_pattern("\\|", false), Ok(())); assert_eq!(validator.validate_pattern("\\/", false), Ok(())); assert_eq!(validator.validate_pattern("\\a", false), Ok(())); assert_eq!(validator.validate_pattern("[]", false), Ok(())); assert_eq!(validator.validate_pattern("[^-a-b-]", false), Ok(())); assert_eq!(validator.validate_pattern("[-]", false), Ok(())); assert_eq!(validator.validate_pattern("[a]", false), Ok(())); assert_eq!(validator.validate_pattern("[--]", false), Ok(())); assert_eq!(validator.validate_pattern("[-a]", false), Ok(())); assert_eq!(validator.validate_pattern("[-a-]", false), Ok(())); assert_eq!(validator.validate_pattern("[a-]", false), Ok(())); assert_eq!(validator.validate_pattern("[a-b]", false), Ok(())); assert_eq!(validator.validate_pattern("[-a-b-]", false), Ok(())); assert_eq!(validator.validate_pattern("[---]", false), Ok(())); assert_eq!(validator.validate_pattern("[a-b--/]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\b-\\n]", false), Ok(())); assert_eq!(validator.validate_pattern("[b\\-a]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\d]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\D]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\s]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\S]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\w]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\W]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\f]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\n]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\r]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\t]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\v]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\cA]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\cz]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\c1]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\c]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\0]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\x]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\xz]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\x1]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\x12]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\x123]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\u]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\u1]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\u12]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\u123]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\u1234]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\u12345]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\u{]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\u{z]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\u{a}]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\u{20]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\u{20}]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\u{10FFFF}]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\u{110000}]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\u{00000001}]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\77]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\377]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\400]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\^]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\$]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\.]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\+]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\?]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\(]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\)]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\[]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\]]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\{]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\}]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\|]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\/]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\a]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\d-\\uFFFF]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\D-\\uFFFF]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\s-\\uFFFF]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\S-\\uFFFF]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\w-\\uFFFF]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\W-\\uFFFF]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\u0000-\\d]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\u0000-\\D]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\u0000-\\s]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\u0000-\\S]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\u0000-\\w]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\u0000-\\W]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\u0000-\\u0001]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\u{2-\\u{1}]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\a-\\z]", false), Ok(())); assert_eq!(validator.validate_pattern("[0-9--/]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\c0-]", false), Ok(())); assert_eq!(validator.validate_pattern("[\\c_]", false), Ok(())); assert_eq!(validator.validate_pattern("^[0-9]*$", false), Ok(())); assert_eq!(validator.validate_pattern("^[0-9]+$", false), Ok(())); assert_eq!(validator.validate_pattern("^[a-zA-Z]*$", false), Ok(())); assert_eq!(validator.validate_pattern("^[a-zA-Z]+$", false), Ok(())); assert_eq!(validator.validate_pattern("^[0-9a-zA-Z]*$", false), Ok(())); assert_eq!(validator.validate_pattern("^[a-zA-Z0-9!-/:-@\\[-`{-~]*$", false), Ok(())); assert_eq!(validator.validate_pattern("^([a-zA-Z0-9]{8,})$", false), Ok(())); assert_eq!(validator.validate_pattern("^([a-zA-Z0-9]{6,8})$", false), Ok(())); assert_eq!(validator.validate_pattern("^([0-9]{0,8})$", false), Ok(())); assert_eq!(validator.validate_pattern("^[0-9]{8}$", false), Ok(())); assert_eq!(validator.validate_pattern("^https?:\\/\\/", false), Ok(())); assert_eq!(validator.validate_pattern("^\\d{3}-\\d{4}$", false), Ok(())); assert_eq!(validator.validate_pattern("^\\d{1,3}(.\\d{1,3}){3}$", false), Ok(())); assert_eq!(validator.validate_pattern("^([1-9][0-9]*|0)(\\.[0-9]+)?$", false), Ok(())); assert_eq!(validator.validate_pattern("^-?([1-9][0-9]*|0)(\\.[0-9]+)?$", false), Ok(())); assert_eq!(validator.validate_pattern("^[ぁ-んー]*$", false), Ok(())); assert_eq!(validator.validate_pattern("^[ァ-ンヴー]*$", false), Ok(())); assert_eq!(validator.validate_pattern("^[ァ-ン゙゚\\-]*$", false), Ok(())); assert_eq!(validator.validate_pattern("^[^\\x20-\\x7e]*$", false), Ok(())); assert_eq!(validator.validate_pattern("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$", false), Ok(())); assert_eq!(validator.validate_pattern("^((4\\d{3})|(5[1-5]\\d{2})|(6011))([- ])?\\d{4}([- ])?\\d{4}([- ])?\\d{4}|3[4,7]\\d{13}$", false), Ok(())); assert_eq!(validator.validate_pattern("^\\s*|\\s*$", false), Ok(())); assert_eq!(validator.validate_pattern("[\\d][\\12-\\14]{1,}[^\\d]", false), Ok(())); assert_eq!(validator.validate_pattern("([a ]\\b)*\\b", false), Ok(())); assert_eq!(validator.validate_pattern("foo", true), Ok(())); assert_eq!(validator.validate_pattern("foo|bar", true), Ok(())); assert_eq!(validator.validate_pattern("||||", true), Ok(())); assert_eq!(validator.validate_pattern("^|$|\\b|\\B", true), Ok(())); assert_eq!(validator.validate_pattern("(?=)", true), Ok(())); assert_eq!(validator.validate_pattern("(?=foo)", true), Ok(())); assert_eq!(validator.validate_pattern("(?!)", true), Ok(())); assert_eq!(validator.validate_pattern("(?!foo)", true), Ok(())); assert_eq!(validator.validate_pattern("a*", true), Ok(())); assert_eq!(validator.validate_pattern("a+", true), Ok(())); assert_eq!(validator.validate_pattern("a?", true), Ok(())); assert_eq!(validator.validate_pattern("a{1}", true), Ok(())); assert_eq!(validator.validate_pattern("a{1,}", true), Ok(())); assert_eq!(validator.validate_pattern("a{1,2}", true), Ok(())); assert_eq!(validator.validate_pattern("a*?", true), Ok(())); assert_eq!(validator.validate_pattern("a+?", true), Ok(())); assert_eq!(validator.validate_pattern("a??", true), Ok(())); assert_eq!(validator.validate_pattern("a{1}?", true), Ok(())); assert_eq!(validator.validate_pattern("a{1,}?", true), Ok(())); assert_eq!(validator.validate_pattern("a{1,2}?", true), Ok(())); assert_eq!(validator.validate_pattern("👍🚀❇️", true), Ok(())); assert_eq!(validator.validate_pattern("^", true), Ok(())); assert_eq!(validator.validate_pattern("$", true), Ok(())); assert_eq!(validator.validate_pattern(".", true), Ok(())); assert_eq!(validator.validate_pattern("|", true), Ok(())); assert_eq!(validator.validate_pattern("(a)\\1", true), Ok(())); assert_eq!(validator.validate_pattern("\\1(a)", true), Ok(())); assert_eq!(validator.validate_pattern("(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)\\10", true), Ok(())); assert_eq!(validator.validate_pattern("(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)(a)\\11", true), Ok(())); assert_eq!(validator.validate_pattern("(?:a)", true), Ok(())); assert_eq!(validator.validate_pattern("\\d", true), Ok(())); assert_eq!(validator.validate_pattern("\\D", true), Ok(())); assert_eq!(validator.validate_pattern("\\s", true), Ok(())); assert_eq!(validator.validate_pattern("\\S", true), Ok(())); assert_eq!(validator.validate_pattern("\\w", true), Ok(())); assert_eq!(validator.validate_pattern("\\W", true), Ok(())); assert_eq!(validator.validate_pattern("\\f", true), Ok(())); assert_eq!(validator.validate_pattern("\\n", true), Ok(())); assert_eq!(validator.validate_pattern("\\r", true), Ok(())); assert_eq!(validator.validate_pattern("\\t", true), Ok(())); assert_eq!(validator.validate_pattern("\\v", true), Ok(())); assert_eq!(validator.validate_pattern("\\cA", true), Ok(())); assert_eq!(validator.validate_pattern("\\cz", true), Ok(())); assert_eq!(validator.validate_pattern("\\0", true), Ok(())); assert_eq!(validator.validate_pattern("\\u1234", true), Ok(())); assert_eq!(validator.validate_pattern("\\u12345", true), Ok(())); assert_eq!(validator.validate_pattern("\\u{a}", true), Ok(())); assert_eq!(validator.validate_pattern("\\u{20}", true), Ok(())); assert_eq!(validator.validate_pattern("\\u{10FFFF}", true), Ok(())); assert_eq!(validator.validate_pattern("\\u{00000001}", true), Ok(())); assert_eq!(validator.validate_pattern("\\^", true), Ok(())); assert_eq!(validator.validate_pattern("\\$", true), Ok(())); assert_eq!(validator.validate_pattern("\\.", true), Ok(())); assert_eq!(validator.validate_pattern("\\+", true), Ok(())); assert_eq!(validator.validate_pattern("\\?", true), Ok(())); assert_eq!(validator.validate_pattern("\\(", true), Ok(())); assert_eq!(validator.validate_pattern("\\)", true), Ok(())); assert_eq!(validator.validate_pattern("\\[", true), Ok(())); assert_eq!(validator.validate_pattern("\\]", true), Ok(())); assert_eq!(validator.validate_pattern("\\{", true), Ok(())); assert_eq!(validator.validate_pattern("\\}", true), Ok(())); assert_eq!(validator.validate_pattern("\\|", true), Ok(())); assert_eq!(validator.validate_pattern("\\/", true), Ok(())); assert_eq!(validator.validate_pattern("[]", true), Ok(())); assert_eq!(validator.validate_pattern("[^-a-b-]", true), Ok(())); assert_eq!(validator.validate_pattern("[-]", true), Ok(())); assert_eq!(validator.validate_pattern("[a]", true), Ok(())); assert_eq!(validator.validate_pattern("[--]", true), Ok(())); assert_eq!(validator.validate_pattern("[-a]", true), Ok(())); assert_eq!(validator.validate_pattern("[-a-]", true), Ok(())); assert_eq!(validator.validate_pattern("[a-]", true), Ok(())); assert_eq!(validator.validate_pattern("[a-b]", true), Ok(())); assert_eq!(validator.validate_pattern("[-a-b-]", true), Ok(())); assert_eq!(validator.validate_pattern("[---]", true), Ok(())); assert_eq!(validator.validate_pattern("[a-b--/]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\b-\\n]", true), Ok(())); assert_eq!(validator.validate_pattern("[b\\-a]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\d]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\D]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\s]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\S]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\w]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\W]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\f]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\n]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\r]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\t]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\v]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\cA]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\cz]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\0]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\x12]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\x123]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\u1234]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\u12345]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\u{a}]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\u{20}]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\u{10FFFF}]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\u{00000001}]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\^]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\$]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\.]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\+]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\?]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\(]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\)]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\[]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\]]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\{]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\}]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\|]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\/]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\u0000-\\u0001]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\u{1}-\\u{2}]", true), Ok(())); assert_eq!(validator.validate_pattern("[0-9--/]", true), Ok(())); assert_eq!(validator.validate_pattern("[🌷-🌸]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\u0000-🌸-\\u0000]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\u0000-\\u{1f338}-\\u0000]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\u0000-\\ud83c\\udf38-\\u0000]", true), Ok(())); assert_eq!(validator.validate_pattern("[\\uD834\\uDF06-\\uD834\\uDF08a-z]", true), Ok(())); assert_eq!(validator.validate_pattern("^[0-9]*$", true), Ok(())); assert_eq!(validator.validate_pattern("^[0-9]+$", true), Ok(())); assert_eq!(validator.validate_pattern("^[a-zA-Z]*$", true), Ok(())); assert_eq!(validator.validate_pattern("^[a-zA-Z]+$", true), Ok(())); assert_eq!(validator.validate_pattern("^[0-9a-zA-Z]*$", true), Ok(())); assert_eq!(validator.validate_pattern("^[a-zA-Z0-9!-/:-@\\[-`{-~]*$", true), Ok(())); assert_eq!(validator.validate_pattern("^([a-zA-Z0-9]{8,})$", true), Ok(())); assert_eq!(validator.validate_pattern("^([a-zA-Z0-9]{6,8})$", true), Ok(())); assert_eq!(validator.validate_pattern("^([0-9]{0,8})$", true), Ok(())); assert_eq!(validator.validate_pattern("^[0-9]{8}$", true), Ok(())); assert_eq!(validator.validate_pattern("^https?:\\/\\/", true), Ok(())); assert_eq!(validator.validate_pattern("^\\d{3}-\\d{4}$", true), Ok(())); assert_eq!(validator.validate_pattern("^\\d{1,3}(.\\d{1,3}){3}$", true), Ok(())); assert_eq!(validator.validate_pattern("^([1-9][0-9]*|0)(\\.[0-9]+)?$", true), Ok(())); assert_eq!(validator.validate_pattern("^-?([1-9][0-9]*|0)(\\.[0-9]+)?$", true), Ok(())); assert_eq!(validator.validate_pattern("^[ぁ-んー]*$", true), Ok(())); assert_eq!(validator.validate_pattern("^[ァ-ンヴー]*$", true), Ok(())); assert_eq!(validator.validate_pattern("^[ァ-ン゙゚\\-]*$", true), Ok(())); assert_eq!(validator.validate_pattern("^[^\\x20-\\x7e]*$", true), Ok(())); assert_eq!(validator.validate_pattern("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$", true), Ok(())); assert_eq!(validator.validate_pattern("^((4\\d{3})|(5[1-5]\\d{2})|(6011))([- ])?\\d{4}([- ])?\\d{4}([- ])?\\d{4}|3[4,7]\\d{13}$", true), Ok(())); assert_eq!(validator.validate_pattern("^\\s*|\\s*$", true), Ok(())); assert_eq!(validator.validate_pattern("(?<=a)", false), Ok(())); assert_eq!(validator.validate_pattern("(?<=a)", true), Ok(())); assert_eq!(validator.validate_pattern("(?\\w){3})f", true), Ok(())); assert_eq!(validator.validate_pattern("((?<=\\w{3}))f", true), Ok(())); assert_eq!(validator.validate_pattern("(?(?<=\\w{3}))f", true), Ok(())); assert_eq!(validator.validate_pattern("(?\\d){3})f", true), Ok(())); assert_eq!(validator.validate_pattern("(?\\D){3})f|f", true), Ok(())); assert_eq!(validator.validate_pattern("(?(?\\w){3})f", false), Ok(())); assert_eq!(validator.validate_pattern("((?<=\\w{3}))f", false), Ok(())); assert_eq!(validator.validate_pattern("(?(?<=\\w{3}))f", false), Ok(())); assert_eq!(validator.validate_pattern("(?\\d){3})f", false), Ok(())); assert_eq!(validator.validate_pattern("(?(?.)|(?.))", true), Ok(())); assert_eq!(validator.validate_pattern("(a)", false), Ok(())); assert_eq!(validator.validate_pattern("(?)", false), Ok(())); assert_eq!(validator.validate_pattern("\\k", false), Ok(())); assert_eq!(validator.validate_pattern("\\k", false), Ok(())); assert_eq!(validator.validate_pattern("(?a)\\k", false), Ok(())); assert_eq!(validator.validate_pattern("(?a)\\k", true), Ok(())); assert_eq!(validator.validate_pattern("(?a)\\1", false), Ok(())); assert_eq!(validator.validate_pattern("(?a)\\1", true), Ok(())); assert_eq!(validator.validate_pattern("(?a)\\2", false), Ok(())); assert_eq!(validator.validate_pattern("(?a)(?a)", false), Ok(())); assert_eq!(validator.validate_pattern("(?a)(?a)", true), Ok(())); assert_eq!(validator.validate_pattern("\\k(?a)", false), Ok(())); assert_eq!(validator.validate_pattern("\\k(?a)", true), Ok(())); assert_eq!(validator.validate_pattern("\\1(?a)", false), Ok(())); assert_eq!(validator.validate_pattern("\\1(?a)", true), Ok(())); assert_eq!(validator.validate_pattern("(?<$abc>a)\\k<$abc>", true), Ok(())); assert_eq!(validator.validate_pattern("(?<あ>a)\\k<あ>", true), Ok(())); assert_eq!(validator.validate_pattern("(?<𠮷>a)\\k<\\u{20bb7}>", true), Ok(())); assert_eq!(validator.validate_pattern("(?<\\uD842\\uDFB7>a)\\k<\\u{20bb7}>", true), Ok(())); assert_eq!(validator.validate_pattern("(?<\\u{20bb7}>a)\\k<\\uD842\\uDFB7>", true), Ok(())); assert_eq!(validator.validate_pattern("(?a)\\k<\\u0061\\u0062\\u0063>", true), Ok(())); assert_eq!(validator.validate_pattern("(?<\\u0061\\u0062\\u0063>a)\\k", true), Ok(())); assert_eq!(validator.validate_pattern("(?<\\u0061\\u0062\\u0063>a)\\k<\\u{61}\\u{62}\\u{63}>", true), Ok(())); assert_eq!(validator.validate_pattern("(?a)\\k", true), Ok(())); assert_eq!(validator.validate_pattern("\\p", false), Ok(())); assert_eq!(validator.validate_pattern("\\p{", false), Ok(())); assert_eq!(validator.validate_pattern("\\p{ASCII", false), Ok(())); assert_eq!(validator.validate_pattern("\\p{ASCII}", false), Ok(())); assert_eq!(validator.validate_pattern("\\p{ASCII}", true), Ok(())); assert_eq!(validator.validate_pattern("\\p{Emoji}", true), Ok(())); assert_eq!(validator.validate_pattern("\\p{General_Category=Letter}", true), Ok(())); assert_eq!(validator.validate_pattern("\\p{Script=Hiragana}", true), Ok(())); assert_eq!(validator.validate_pattern("[\\p{Script=Hiragana}\\-\\p{Script=Katakana}]", true), Ok(())); assert_eq!(validator.validate_pattern("\\P{Letter}", true), Ok(())); }