Bug 1931736. Add missing braces around if/loop statements in layout/xul/. r=layout...
[gecko.git] / js / src / jsapi-tests / testRegExp.cpp
blob9a2b6f665fa3d72d4b69819566fc738aa7b9ceac
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "js/RegExp.h"
6 #include "js/RegExpFlags.h"
7 #include "jsapi-tests/tests.h"
9 BEGIN_TEST(testObjectIsRegExp) {
10 JS::RootedValue val(cx);
12 bool isRegExp;
14 EVAL("new Object", &val);
15 JS::RootedObject obj(cx, val.toObjectOrNull());
16 CHECK(JS::ObjectIsRegExp(cx, obj, &isRegExp));
17 CHECK(!isRegExp);
19 EVAL("/foopy/", &val);
20 obj = val.toObjectOrNull();
21 CHECK(JS::ObjectIsRegExp(cx, obj, &isRegExp));
22 CHECK(isRegExp);
24 return true;
26 END_TEST(testObjectIsRegExp)
28 BEGIN_TEST(testGetRegExpFlags) {
29 JS::RootedValue val(cx);
30 JS::RootedObject obj(cx);
32 EVAL("/foopy/", &val);
33 obj = val.toObjectOrNull();
34 CHECK_EQUAL(JS::GetRegExpFlags(cx, obj),
35 JS::RegExpFlags(JS::RegExpFlag::NoFlags));
37 EVAL("/foopy/g", &val);
38 obj = val.toObjectOrNull();
39 CHECK_EQUAL(JS::GetRegExpFlags(cx, obj),
40 JS::RegExpFlags(JS::RegExpFlag::Global));
42 EVAL("/foopy/gi", &val);
43 obj = val.toObjectOrNull();
44 CHECK_EQUAL(
45 JS::GetRegExpFlags(cx, obj),
46 JS::RegExpFlags(JS::RegExpFlag::Global | JS::RegExpFlag::IgnoreCase));
48 return true;
50 END_TEST(testGetRegExpFlags)
52 BEGIN_TEST(testGetRegExpSource) {
53 JS::RootedValue val(cx);
54 JS::RootedObject obj(cx);
56 EVAL("/foopy/", &val);
57 obj = val.toObjectOrNull();
58 JSString* source = JS::GetRegExpSource(cx, obj);
59 CHECK(source);
60 CHECK(JS_LinearStringEqualsLiteral(JS_ASSERT_STRING_IS_LINEAR(source),
61 "foopy"));
63 return true;
65 END_TEST(testGetRegExpSource)