Files
wehub-resource-sync e7738de6d2
CI / Deep Native Runtime Cases (1/6) (push) Has been skipped
CI / Native Preflight (push) Failing after 1s
CI / Native Runtime Cases (1/2) (push) Failing after 0s
CI / Native Runtime Cases (2/2) (push) Failing after 1s
CI / Native Metadata Reports (push) Failing after 0s
CI / Native Direct Backend Artifacts (push) Failing after 0s
CI / Native Sanitizer Smoke (push) Failing after 1s
CI / Command Contract Snapshots (push) Failing after 1s
CI / Deep Conformance Suite (push) Has been skipped
CI / Graph Build Perf (push) Failing after 1s
CI / Deep Native Preflight (push) Has been skipped
CI / Deep Native Runtime Cases (2/6) (push) Has been skipped
CI / Deep Native Runtime Cases (3/6) (push) Has been skipped
CI / Conformance Suite (push) Failing after 1s
CI / Workspace Checks (push) Failing after 0s
CI / Deep Native Runtime Cases (5/6) (push) Has been skipped
CI / Deep Native Runtime Cases (6/6) (push) Has been skipped
CI / Deep Native Runtime Cases (4/6) (push) Has been skipped
CI / Deep Graph Build Perf (push) Has been skipped
chore: import upstream snapshot with attribution
2026-07-13 12:29:30 +08:00

155 lines
5.3 KiB
Plaintext

fn regex_compile_and_match() -> Bool {
var storage: [512]u8 = [0; 512]
let buffer: MutSpan<u8> = storage
let compiled: Maybe<Span<u8>> = std.regex.compile(buffer, "^h[ae]llo{1,2}$")
if !compiled.has {
return false
}
let program: Span<u8> = compiled.value
if !std.regex.isMatch(program, "hello") || !std.regex.isMatch(program, "halloo") {
return false
}
return !std.regex.isMatch(program, "hullo") && !std.regex.isMatch(program, "hellooo")
}
fn regex_one_shot() -> Bool {
let digits: Maybe<Bool> = std.regex.matches("^\\d{3}-\\d{4}$", "555-0199")
if !digits.has || !digits.value {
return false
}
let alternation: Maybe<Bool> = std.regex.matches("^(cat|dog)s?$", "dogs")
if !alternation.has || !alternation.value {
return false
}
let unanchored: Maybe<Bool> = std.regex.matches("wor\\w+", "hello world")
if !unanchored.has || !unanchored.value {
return false
}
let miss: Maybe<Bool> = std.regex.matches("^[0-9a-f]{4}$", "12g4")
if !miss.has || miss.value {
return false
}
let invalid: Maybe<Bool> = std.regex.matches("(unclosed", "text")
return !invalid.has
}
fn regex_search() -> Bool {
let contains: Maybe<Bool> = std.regex.contains("cat|dog", "hot dog")
if !contains.has || !contains.value {
return false
}
let missing_contains: Maybe<Bool> = std.regex.contains("cat|dog", "bird")
if !missing_contains.has || missing_contains.value {
return false
}
let index: Maybe<usize> = std.regex.findIndex("wor\\w+", "hello world")
if !index.has || index.value != 6 {
return false
}
let missing_index: Maybe<usize> = std.regex.findIndex("^world", "hello world")
if !missing_index.has || missing_index.value != std.mem.len("hello world") {
return false
}
let found: Maybe<Span<u8>> = std.regex.find("\\d+", "build-2048")
if !found.has || !std.mem.eql(found.value, "2048") {
return false
}
let count: Maybe<usize> = std.regex.findCount("\\d+", "a1 b22 c333")
if !count.has || count.value != 3 {
return false
}
let second: Maybe<Span<u8>> = std.regex.findNth("\\d+", "a1 b22 c333", 1)
if !second.has || !std.mem.eql(second.value, "22") {
return false
}
let second_index: Maybe<usize> = std.regex.findNthIndex("\\d+", "a1 b22 c333", 1)
if !second_index.has || second_index.value != 4 {
return false
}
let ambiguous: Maybe<Span<u8>> = std.regex.find("a|ab", "ab")
if !ambiguous.has || !std.mem.eql(ambiguous.value, "ab") {
return false
}
var ambiguous_replace_storage: [4]u8 = [0; 4]
let ambiguous_replaced: Maybe<Span<u8>> = std.regex.replace(ambiguous_replace_storage, "a|ab", "ab", "#")
if !ambiguous_replaced.has || !std.mem.eql(ambiguous_replaced.value, "#") {
return false
}
var replaced_storage: [16]u8 = [0; 16]
let replaced: Maybe<Span<u8>> = std.regex.replace(replaced_storage, "\\d+", "a1 b22", "#")
if !replaced.has || !std.mem.eql(replaced.value, "a# b#") {
return false
}
let fields: Maybe<usize> = std.regex.splitCount("[,;]", "red,green;blue")
if !fields.has || fields.value != 3 {
return false
}
let middle: Maybe<Span<u8>> = std.regex.split("[,;]", "red,green;blue", 1)
if !middle.has || !std.mem.eql(middle.value, "green") {
return false
}
let trailing: Maybe<Span<u8>> = std.regex.split(",", "red,", 1)
if !trailing.has || !std.mem.eql(trailing.value, "") {
return false
}
let invalid: Maybe<usize> = std.regex.findIndex("(unclosed", "text")
return !invalid.has
}
fn regex_codepoints() -> Bool {
let accent: Maybe<Bool> = std.regex.matches("^.é$", "xé")
if !accent.has || !accent.value {
return false
}
let emoji: Maybe<Bool> = std.regex.matches("^.$", "💯")
return emoji.has && emoji.value
}
fn regex_statuses() -> Bool {
var storage: [128]u8 = [0; 128]
let buffer: MutSpan<u8> = storage
if std.regex.compileStatus(buffer, "a+b*") != 0 {
return false
}
if std.regex.compileStatus(buffer, "(a)\\1") != 1 {
return false
}
if std.regex.compileStatus(buffer, "(?=ahead)") != 2 {
return false
}
if std.regex.compileStatus(buffer, "(?<=behind)") != 3 {
return false
}
if std.regex.compileStatus(buffer, "(?<name>x)") != 4 {
return false
}
if std.regex.compileStatus(buffer, "a+?") != 5 {
return false
}
if std.regex.compileStatus(buffer, "(?i)x") != 6 {
return false
}
if std.regex.compileStatus(buffer, "\\p{L}") != 7 {
return false
}
if std.regex.compileStatus(buffer, "(a") != 8 {
return false
}
let offset: Maybe<usize> = std.regex.compileErrorOffset(buffer, "(a")
if !offset.has || offset.value != 2 {
return false
}
if std.regex.compileStatus(buffer, "a{4,2}") != 9 {
return false
}
return std.mem.eql(std.regex.statusName(2), "unsupported lookahead") && std.mem.eql(std.regex.statusName(0), "ok")
}
pub fn main(world: World) -> Void raises {
if regex_compile_and_match() && regex_one_shot() && (regex_search() && (regex_codepoints() && regex_statuses())) {
check world.out.write("std regex ok\n")
} else {
check world.out.write("std regex failed\n")
}
}