// |reftest| shell-option(--enable-regexp-buffer-boundaries) skip-if(release_or_beta||!xulRuntime.shell) -- regexp-buffer-boundaries is not released yet, requires shell-options // Copyright 2026 Ron Buckton. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- author: Ron Buckton description: > `\z` (lower-case z) matches end of buffer in v-mode. info: | Runtime Semantics: CompileAssertion Assertion :: \z 1. Return a new Matcher with parameters (matchState, continue) that captures nothing and performs the following steps when called: a. Assert: matchState is a MatchState. b. Assert: continue is a MatcherContinuation. c. Let input be matchState.[[Input]]. d. Let e be matchState.[[EndIndex]]. e. Let inputLength be the number of elements in input. f. If e = inputLength, return continue(matchState). g. Return failure. esid: sec-patterns features: [regexp-buffer-boundaries, regexp-v-flag] ---*/ assert(/x\z/v.test("x"), "Expected \\z to match end-of-buffer outside of multiline mode (literal)"); assert(/x\z/vm.test("x"), "Expected \\z to match end-of-buffer inside of multiline mode (literal)"); assert(!/x\z/v.test("xy"), "Expected \\z to not match when not at end-of-buffer outside of multiline mode (literal)"); assert(!/x\z/vm.test("xy"), "Expected \\z to not match when not at end-of-buffer inside of multiline mode (literal)"); var terminators = [ ["\n", ""], ["\r", ""], ["\u2028", ""], ["\u2029", ""], ["\r\n", ""], ]; for (var i = 0; i < terminators.length; i++) { var lts = terminators[i][0], desc = terminators[i][1]; assert(!/x\z/v.test("x" + lts), "Expected \\z to not match when only at " + desc + " outside of multiline mode (literal)"); assert(!/x\z/vm.test("x" + lts), "Expected \\z to not match when only at " + desc + " inside of multiline mode (literal)"); } assert(new RegExp("x\\z", "v").test("x"), "Expected \\z to match end-of-buffer outside of multiline mode (constructed)"); assert(new RegExp("x\\z", "vm").test("x"), "Expected \\z to match end-of-buffer inside of multiline mode (constructed)"); assert(!new RegExp("x\\z", "v").test("xy"), "Expected \\z to not match when not at end-of-buffer outside of multiline mode (constructed)"); assert(!new RegExp("x\\z", "vm").test("xy"), "Expected \\z to not match when not at end-of-buffer inside of multiline mode (constructed)"); for (var i = 0; i < terminators.length; i++) { var lts = terminators[i][0], desc = terminators[i][1]; assert(!new RegExp("x\\z", "v").test("x" + lts), "Expected \\z to not match when only at " + desc + " outside of multiline mode (constructed)"); assert(!new RegExp("x\\z", "vm").test("x" + lts), "Expected \\z to not match when only at " + desc + " inside of multiline mode (constructed)"); } reportCompare(0, 0);