2020-08-01 03:43:15 +02:00
|
|
|
|
"use strict";
|
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
|
2020-12-01 00:02:16 +01:00
|
|
|
|
const {zrequire} = require("../zjsunit/namespace");
|
2020-12-01 00:39:47 +01:00
|
|
|
|
const {run_test} = require("../zjsunit/test");
|
2021-03-05 16:35:06 +01:00
|
|
|
|
const $ = require("../zjsunit/zjquery");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
|
const rtl = zrequire("rtl");
|
2017-04-17 23:40:36 +02:00
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
|
run_test("get_direction", () => {
|
2017-04-17 23:40:36 +02:00
|
|
|
|
// These characters are strong R or AL: ا ب پ ج ض و د ؛
|
|
|
|
|
// These characters are not strong: ۱ ۲ ۳ ۴ ۵ ۶ ۷ ۸ ۹ ۰
|
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
|
assert.equal(rtl.get_direction("abcابپ"), "ltr");
|
|
|
|
|
assert.equal(rtl.get_direction("ابپabc"), "rtl");
|
|
|
|
|
assert.equal(rtl.get_direction("123abc"), "ltr");
|
|
|
|
|
assert.equal(rtl.get_direction("۱۲۳abc"), "ltr");
|
|
|
|
|
assert.equal(rtl.get_direction("123؛بپ"), "rtl");
|
|
|
|
|
assert.equal(rtl.get_direction("۱۲۳ابپ"), "rtl");
|
|
|
|
|
assert.equal(rtl.get_direction("۱۲جg"), "rtl");
|
|
|
|
|
assert.equal(rtl.get_direction("12gج"), "ltr");
|
|
|
|
|
assert.equal(rtl.get_direction("۱۲۳"), "ltr");
|
|
|
|
|
assert.equal(rtl.get_direction("1234"), "ltr");
|
2017-04-17 23:40:36 +02:00
|
|
|
|
|
2020-10-07 10:24:09 +02:00
|
|
|
|
const supp_plane_ltr_char = "\uD800\uDFA0";
|
|
|
|
|
const supp_plane_rtl_char = "\uD802\uDC40";
|
2018-08-11 05:44:30 +02:00
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
|
assert.equal(rtl.get_direction(supp_plane_ltr_char), "ltr");
|
|
|
|
|
assert.equal(rtl.get_direction(supp_plane_rtl_char), "rtl");
|
|
|
|
|
assert.equal(rtl.get_direction("123" + supp_plane_ltr_char), "ltr");
|
|
|
|
|
assert.equal(rtl.get_direction("123" + supp_plane_rtl_char), "rtl");
|
|
|
|
|
assert.equal(rtl.get_direction(supp_plane_ltr_char + supp_plane_rtl_char), "ltr");
|
|
|
|
|
assert.equal(rtl.get_direction(supp_plane_rtl_char + supp_plane_ltr_char), "rtl");
|
|
|
|
|
assert.equal(rtl.get_direction(supp_plane_ltr_char + " " + supp_plane_rtl_char), "ltr");
|
|
|
|
|
assert.equal(rtl.get_direction(supp_plane_rtl_char + " " + supp_plane_ltr_char), "rtl");
|
|
|
|
|
assert.equal(rtl.get_direction(supp_plane_ltr_char + "ج" + supp_plane_rtl_char), "ltr");
|
|
|
|
|
assert.equal(rtl.get_direction(supp_plane_rtl_char + "ج" + supp_plane_ltr_char), "rtl");
|
|
|
|
|
assert.equal(rtl.get_direction("پ" + supp_plane_ltr_char + "." + supp_plane_rtl_char), "rtl");
|
|
|
|
|
assert.equal(rtl.get_direction("پ" + supp_plane_rtl_char + "." + supp_plane_ltr_char), "rtl");
|
|
|
|
|
assert.equal(rtl.get_direction("b" + supp_plane_ltr_char + "." + supp_plane_rtl_char), "ltr");
|
|
|
|
|
assert.equal(rtl.get_direction("b" + supp_plane_rtl_char + "." + supp_plane_ltr_char), "ltr");
|
2018-08-11 05:44:30 +02:00
|
|
|
|
|
2020-10-07 10:24:09 +02:00
|
|
|
|
const unmatched_surrogate_1 = "\uD800";
|
|
|
|
|
const unmatched_surrogate_2 = "\uDF00";
|
2018-08-11 05:44:30 +02:00
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
|
assert.equal(rtl.get_direction(unmatched_surrogate_1 + " "), "ltr");
|
|
|
|
|
assert.equal(rtl.get_direction(unmatched_surrogate_2 + " "), "ltr");
|
|
|
|
|
assert.equal(rtl.get_direction(" " + unmatched_surrogate_1), "ltr");
|
|
|
|
|
assert.equal(rtl.get_direction(" " + unmatched_surrogate_2), "ltr");
|
|
|
|
|
assert.equal(rtl.get_direction(" " + unmatched_surrogate_1 + " "), "ltr");
|
|
|
|
|
assert.equal(rtl.get_direction(" " + unmatched_surrogate_2 + " "), "ltr");
|
|
|
|
|
assert.equal(rtl.get_direction(unmatched_surrogate_1 + supp_plane_ltr_char), "ltr");
|
|
|
|
|
assert.equal(rtl.get_direction(unmatched_surrogate_1 + supp_plane_rtl_char), "ltr");
|
|
|
|
|
assert.equal(rtl.get_direction(unmatched_surrogate_2 + supp_plane_ltr_char), "ltr");
|
|
|
|
|
assert.equal(rtl.get_direction(unmatched_surrogate_2 + supp_plane_rtl_char), "ltr");
|
|
|
|
|
assert.equal(rtl.get_direction(supp_plane_ltr_char + unmatched_surrogate_1), "ltr");
|
|
|
|
|
assert.equal(rtl.get_direction(supp_plane_ltr_char + unmatched_surrogate_2), "ltr");
|
|
|
|
|
assert.equal(rtl.get_direction(supp_plane_rtl_char + unmatched_surrogate_1), "rtl");
|
|
|
|
|
assert.equal(rtl.get_direction(supp_plane_rtl_char + unmatched_surrogate_2), "rtl");
|
2018-08-11 05:44:30 +02:00
|
|
|
|
|
2017-04-17 23:40:36 +02:00
|
|
|
|
// Testing with some isolate initiators and PDIs.
|
2020-07-15 01:29:15 +02:00
|
|
|
|
const i_chars = "\u2066\u2067\u2068";
|
|
|
|
|
const pdi = "\u2069";
|
2017-04-17 23:40:36 +02:00
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
|
assert.equal(rtl.get_direction("aa" + i_chars.charAt(0) + "bb" + pdi + "cc"), "ltr");
|
|
|
|
|
assert.equal(rtl.get_direction("دد" + i_chars.charAt(0) + "bb" + pdi + "cc"), "rtl");
|
|
|
|
|
assert.equal(rtl.get_direction("12" + i_chars.charAt(0) + "bb" + pdi + "جج"), "rtl");
|
|
|
|
|
assert.equal(rtl.get_direction("۱۲" + i_chars.charAt(0) + "جج" + pdi + "cc"), "ltr");
|
|
|
|
|
assert.equal(rtl.get_direction("aa" + i_chars.charAt(0) + "ج؛ج"), "ltr");
|
|
|
|
|
assert.equal(rtl.get_direction("12" + i_chars.charAt(0) + "ج؛ج"), "ltr");
|
|
|
|
|
assert.equal(rtl.get_direction("۱۲" + i_chars.charAt(0) + "aaa"), "ltr");
|
2020-07-15 00:34:28 +02:00
|
|
|
|
assert.equal(
|
|
|
|
|
rtl.get_direction(
|
|
|
|
|
",," + i_chars.charAt(0) + "bb" + i_chars.charAt(0) + "جج" + pdi + "ضض" + pdi + "..",
|
|
|
|
|
),
|
|
|
|
|
"ltr",
|
|
|
|
|
);
|
|
|
|
|
assert.equal(
|
|
|
|
|
rtl.get_direction(
|
|
|
|
|
",," + i_chars.charAt(0) + "bb" + i_chars.charAt(0) + "جج" + pdi + "ضض" + pdi + "وو",
|
|
|
|
|
),
|
|
|
|
|
"rtl",
|
|
|
|
|
);
|
|
|
|
|
assert.equal(
|
|
|
|
|
rtl.get_direction(",," + i_chars.charAt(0) + "bb" + pdi + "33" + pdi + ".."),
|
|
|
|
|
"ltr",
|
|
|
|
|
);
|
|
|
|
|
assert.equal(
|
|
|
|
|
rtl.get_direction(",," + i_chars.charAt(0) + "bb" + pdi + "12" + pdi + "وو"),
|
|
|
|
|
"rtl",
|
|
|
|
|
);
|
|
|
|
|
assert.equal(
|
|
|
|
|
rtl.get_direction(",," + i_chars.charAt(0) + "ضج" + pdi + "12" + pdi + "ff"),
|
|
|
|
|
"ltr",
|
|
|
|
|
);
|
2017-04-17 23:40:36 +02:00
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
|
assert.equal(rtl.get_direction("aa" + i_chars.charAt(1) + "bb" + pdi + "cc"), "ltr");
|
|
|
|
|
assert.equal(rtl.get_direction("دد" + i_chars.charAt(2) + "bb" + pdi + "cc"), "rtl");
|
|
|
|
|
assert.equal(rtl.get_direction("12" + i_chars.charAt(1) + "bb" + pdi + "جج"), "rtl");
|
|
|
|
|
assert.equal(rtl.get_direction("۱۲" + i_chars.charAt(2) + "جج" + pdi + "cc"), "ltr");
|
|
|
|
|
assert.equal(rtl.get_direction("aa" + i_chars.charAt(1) + "ججج"), "ltr");
|
|
|
|
|
assert.equal(rtl.get_direction("12" + i_chars.charAt(2) + "ججج"), "ltr");
|
|
|
|
|
assert.equal(rtl.get_direction("۱۲" + i_chars.charAt(1) + "aaa"), "ltr");
|
2020-07-15 00:34:28 +02:00
|
|
|
|
assert.equal(
|
|
|
|
|
rtl.get_direction(
|
|
|
|
|
",," + i_chars.charAt(1) + "bb" + i_chars.charAt(2) + "جج" + pdi + "ضض" + pdi + "..",
|
|
|
|
|
),
|
|
|
|
|
"ltr",
|
|
|
|
|
);
|
|
|
|
|
assert.equal(
|
|
|
|
|
rtl.get_direction(
|
|
|
|
|
",," + i_chars.charAt(2) + "bb" + i_chars.charAt(1) + "؛ج" + pdi + "ضض" + pdi + "وو",
|
|
|
|
|
),
|
|
|
|
|
"rtl",
|
|
|
|
|
);
|
|
|
|
|
assert.equal(
|
|
|
|
|
rtl.get_direction(",," + i_chars.charAt(1) + "bb" + pdi + "33" + pdi + ".."),
|
|
|
|
|
"ltr",
|
|
|
|
|
);
|
|
|
|
|
assert.equal(
|
|
|
|
|
rtl.get_direction(",," + i_chars.charAt(2) + "bb" + pdi + "12" + pdi + "وو"),
|
|
|
|
|
"rtl",
|
|
|
|
|
);
|
|
|
|
|
assert.equal(
|
|
|
|
|
rtl.get_direction(",," + i_chars.charAt(1) + "ضج" + pdi + "12" + pdi + "ff"),
|
|
|
|
|
"ltr",
|
|
|
|
|
);
|
2018-05-15 12:40:07 +02:00
|
|
|
|
});
|
2021-03-05 16:35:06 +01:00
|
|
|
|
|
|
|
|
|
run_test("set_rtl_class_for_textarea rtl", () => {
|
2022-01-25 11:36:19 +01:00
|
|
|
|
const $textarea = $.create("some-textarea");
|
|
|
|
|
assert.ok(!$textarea.hasClass("rtl"));
|
2021-03-05 16:35:06 +01:00
|
|
|
|
const text = "```quote\nمرحبا";
|
2022-01-25 11:36:19 +01:00
|
|
|
|
$textarea.val(text);
|
|
|
|
|
rtl.set_rtl_class_for_textarea($textarea);
|
|
|
|
|
assert.ok($textarea.hasClass("rtl"));
|
2021-03-05 16:35:06 +01:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
run_test("set_rtl_class_for_textarea ltr", () => {
|
2022-01-25 11:36:19 +01:00
|
|
|
|
const $textarea = $.create("some-textarea");
|
|
|
|
|
$textarea.addClass("rtl");
|
|
|
|
|
assert.ok($textarea.hasClass("rtl"));
|
2021-03-05 16:35:06 +01:00
|
|
|
|
const text = "```quote\nEnglish text";
|
2022-01-25 11:36:19 +01:00
|
|
|
|
$textarea.val(text);
|
|
|
|
|
rtl.set_rtl_class_for_textarea($textarea);
|
|
|
|
|
assert.ok(!$textarea.hasClass("rtl"));
|
2021-03-05 16:35:06 +01:00
|
|
|
|
});
|