From 732b063dcd7f3e1616298f33d9c8ddfe4c5d395e Mon Sep 17 00:00:00 2001 From: Nils Dagsson Moskopp Date: Sun, 26 Mar 2023 20:46:38 +0200 Subject: [PATCH] + Add tests for bidi rule W4 --- bidi.lua | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/bidi.lua b/bidi.lua index 1c069ce..d98eb9b 100644 --- a/bidi.lua +++ b/bidi.lua @@ -230,7 +230,7 @@ assert( "R" == test_output[3].bidi_class ) -bidi.W4 = function(run) +local W4 = function(run) for i = 1, #run do if "ES" == run[i].bidi_class then -- A single European separator between two European numbers @@ -268,6 +268,45 @@ bidi.W4 = function(run) return run end +-- Test W4: EN ES EN → EN EN EN +local test_input = { + { ["bidi_class"] = "EN" }, + { ["bidi_class"] = "ES" }, + { ["bidi_class"] = "EN" }, +} +local test_output = W4(test_input) +assert( + "EN" == test_output[1].bidi_class and + "EN" == test_output[2].bidi_class and + "EN" == test_output[3].bidi_class +) + +-- Test W4: EN CS EN → EN EN EN +local test_input = { + { ["bidi_class"] = "EN" }, + { ["bidi_class"] = "CS" }, + { ["bidi_class"] = "EN" }, +} +local test_output = W4(test_input) +assert( + "EN" == test_output[1].bidi_class and + "EN" == test_output[2].bidi_class and + "EN" == test_output[3].bidi_class +) + +-- Test W4: AN CS AN → AN AN AN +local test_input = { + { ["bidi_class"] = "AN" }, + { ["bidi_class"] = "CS" }, + { ["bidi_class"] = "AN" }, +} +local test_output = W4(test_input) +assert( + "AN" == test_output[1].bidi_class and + "AN" == test_output[2].bidi_class and + "AN" == test_output[3].bidi_class +) + bidi.W5 = function(run) for i = 1, #run do if "ET" == run[i].bidi_class then @@ -337,7 +376,7 @@ bidi.resolve_weak_types = function(run, sos) run = bidi.W1(run, sos) run = W2(run, sos) run = W3(run) - run = bidi.W4(run) + run = W4(run) run = bidi.W5(run) run = bidi.W6(run) run = bidi.W7(run, sos)