summaryrefslogtreecommitdiffstats
path: root/test/helpers/regExpEscapeSpec.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/helpers/regExpEscapeSpec.js')
-rw-r--r--test/helpers/regExpEscapeSpec.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/helpers/regExpEscapeSpec.js b/test/helpers/regExpEscapeSpec.js
new file mode 100644
index 0000000..c50167b
--- /dev/null
+++ b/test/helpers/regExpEscapeSpec.js
@@ -0,0 +1,38 @@
+describe("Awesomplete.$.regExpEscape", function () {
+
+ subject(function () { return Awesomplete.$.regExpEscape(this.str) });
+
+ describe("with regular expression special characters", function () {
+ it("escapes backslashes", function () {
+ this.str = "\\";
+ expect(this.subject).toBe("\\\\");
+ });
+
+ it("escapes brackets, braces and parentheses", function () {
+ this.str = "[]{}()";
+ expect(this.subject).toBe("\\[\\]\\{\\}\\(\\)");
+ });
+
+ it("escapes other special characters", function () {
+ this.str = "-^$*+?.|";
+ expect(this.subject).toBe("\\-\\^\\$\\*\\+\\?\\.\\|");
+ });
+
+ it("escapes the whole string", function () {
+ this.str = "**";
+ expect(this.subject).toBe("\\*\\*");
+ });
+ });
+
+ describe("with plain characters", function () {
+ it("does not escape letters", function () {
+ this.str = "abcdefjhijklmnopqrstuvwxyzABCDEFJHIJKLMNOPQRSTUVWXYZ";
+ expect(this.subject).toBe(this.str);
+ });
+
+ it("does not escape numbers", function () {
+ this.str = "0123456789";
+ expect(this.subject).toBe(this.str);
+ });
+ });
+});