mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Html: Move get_elem_val to xo.elem
This commit is contained in:
116
400_xowa/src/gplx/xowa/langs/numbers/Xol_num_fmtr_base_tst.java
Normal file
116
400_xowa/src/gplx/xowa/langs/numbers/Xol_num_fmtr_base_tst.java
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.langs.numbers; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
|
||||
import org.junit.*;
|
||||
public class Xol_num_fmtr_base_tst {
|
||||
Xol_num_fmtr_base mgr = new Xol_num_fmtr_base();
|
||||
@Before public void init() {mgr.Clear();}
|
||||
@Test public void Outliers() {
|
||||
ini_(".", dat_(",", 3));
|
||||
tst_Fmt("1234a1234" , "1,234a1,234");
|
||||
tst_Fmt("1234abc1234" , "1,234abc1,234");
|
||||
tst_Fmt("1234,1234" , "1,234,1,234");
|
||||
tst_Fmt("1234.1234" , "1,234.1234");
|
||||
tst_Fmt("1234." , "1,234.");
|
||||
tst_Fmt("1234.1234.1234.1234" , "1,234.1234.1234.1234");
|
||||
tst_Fmt("-1234567" , "-1,234,567");
|
||||
tst_Fmt("1,234,567" , "1,234,567");
|
||||
}
|
||||
@Test public void English() {
|
||||
ini_(".", dat_(",", 3));
|
||||
tst_Fmt("123" , "123");
|
||||
tst_Fmt("1234" , "1,234");
|
||||
tst_Fmt("12345678" , "12,345,678");
|
||||
tst_Fmt("12345678901234567890" , "12,345,678,901,234,567,890");
|
||||
tst_Raw("1,234.12" , "1234.12");
|
||||
}
|
||||
@Test public void French() {
|
||||
ini_(",", dat_(" ", 3));
|
||||
tst_Fmt("123" , "123");
|
||||
tst_Fmt("1234" , "1 234");
|
||||
tst_Fmt("12345678" , "12 345 678");
|
||||
tst_Fmt("12345678901234567890" , "12 345 678 901 234 567 890");
|
||||
tst_Fmt("1234,5678" , "1 234 5 678"); // NOTE: nbsp here; also, nbsp is repeated. see dewiki and {{formatnum:1234,56}}
|
||||
}
|
||||
@Test public void Croatia() {
|
||||
ini_(",", dat_(".", 3), dat_(",", 3));
|
||||
tst_Fmt("123" , "123");
|
||||
tst_Fmt("1234" , "1.234");
|
||||
tst_Fmt("12345678" , "12,345.678");
|
||||
tst_Fmt("12345678901234567890" , "12,345.678,901.234,567.890");
|
||||
}
|
||||
@Test public void Mexico() {
|
||||
ini_(".", dat_(",", 3, false), dat_("'", 3, false), dat_(",", 3));
|
||||
tst_Fmt("123" , "123");
|
||||
tst_Fmt("1234" , "1,234");
|
||||
tst_Fmt("12345678" , "12'345,678");
|
||||
tst_Fmt("12345678901234567890" , "12,345,678,901,234'567,890");
|
||||
tst_Raw("12'345,678.90" , "12345678.90");
|
||||
}
|
||||
@Test public void China() {
|
||||
ini_(".", dat_(",", 4));
|
||||
tst_Fmt("123" , "123");
|
||||
tst_Fmt("1234" , "1234");
|
||||
tst_Fmt("12345678" , "1234,5678");
|
||||
tst_Fmt("12345678901234567890" , "1234,5678,9012,3456,7890");
|
||||
}
|
||||
@Test public void Hindi() {
|
||||
ini_(".", dat_(",", 3, false), dat_(",", 2));
|
||||
tst_Fmt("123" , "123");
|
||||
tst_Fmt("1234" , "1,234");
|
||||
tst_Fmt("12345678" , "1,23,45,678");
|
||||
tst_Fmt("12345678901234567890" , "1,23,45,67,89,01,23,45,67,890");
|
||||
}
|
||||
@Test public void India() {
|
||||
ini_(".", dat_(",", 3), dat_(",", 2), dat_(",", 2));
|
||||
tst_Fmt("123" , "123");
|
||||
tst_Fmt("1234" , "1,234");
|
||||
tst_Fmt("12345678" , "1,23,45,678");
|
||||
tst_Fmt("12345678901234567890" , "1,23,456,78,90,123,45,67,890");
|
||||
}
|
||||
@Test public void MiddleDot() {
|
||||
ini_("·", dat_("·", 3));
|
||||
tst_Fmt("123" , "123");
|
||||
tst_Fmt("1234" , "1·234");
|
||||
tst_Fmt("12345678" , "12·345·678");
|
||||
tst_Fmt("12345678901234567890" , "12·345·678·901·234·567·890");
|
||||
tst_Fmt("1234·5678" , "1·234·5·678");// NOTE: middle-dot is repeated. see dewiki and {{formatnum:1234,5678}}
|
||||
tst_Raw("1234·5678" , "1234.5678");
|
||||
}
|
||||
Xol_num_grp dat_(String dlm, int digits) {return new Xol_num_grp(Bry_.new_u8(dlm), digits, true);}
|
||||
Xol_num_grp dat_(String dlm, int digits, boolean repeat) {return new Xol_num_grp(Bry_.new_u8(dlm), digits, repeat);}
|
||||
private void tst_Fmt(String val, String expd) {Tfds.Eq(expd, String_.new_u8(mgr.Fmt(Bry_.new_u8(val))));}
|
||||
private void tst_Raw(String val, String expd) {Tfds.Eq(expd, String_.new_u8(mgr.Raw(Xol_num_fmtr_base.Tid_raw, Bry_.new_u8(val))));}
|
||||
private void ini_(String dec_dlm, Xol_num_grp... ary) {
|
||||
mgr.Dec_dlm_(Bry_.new_u8(dec_dlm));
|
||||
int ary_len = ary.length;
|
||||
for (int i = 0; i < ary_len; i++)
|
||||
mgr.Grps_add(ary[i]);
|
||||
}
|
||||
}
|
||||
/*
|
||||
'france' ' 3#' ',0%' // 1 234 567,89
|
||||
'spain' '.3#' "'0%" // 1.234.567'89
|
||||
'germany' '.3#' ",0%" // 1.234.567,89
|
||||
'italy' ''3#' ",0%" // 1'234'567,89
|
||||
'en-us' ',3#' '.0%' // 1,234,567.89
|
||||
'en-sa' ',3#' '\u00120%' // 1,234,567·89
|
||||
'croatia' ',3#*' '.3#*' ',0%' // 1,234.567,890.123,45
|
||||
'china' ',4$' // 123,4567.89
|
||||
'mexico' ',3#*' "'3#" ',3#' // 1'234,567.89
|
||||
'hindi' ",2#*" ',3#' // 1,23,45,678.9
|
||||
'india' ',2#*' ',2#*' ',3#*' // 1,245,67,89,012
|
||||
*/
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012-2017 gnosygnu@gmail.com
|
||||
|
||||
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
|
||||
or alternatively under the terms of the Apache License Version 2.0.
|
||||
|
||||
You may use XOWA according to either of these licenses as is most appropriate
|
||||
for your project on a case-by-case basis.
|
||||
|
||||
The terms of each license can be found in the source code repository:
|
||||
|
||||
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
|
||||
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
||||
*/
|
||||
package gplx.xowa.langs.numbers; import gplx.*; import gplx.xowa.*; import gplx.xowa.langs.*;
|
||||
import org.junit.*;
|
||||
public class Xol_num_grp_fmtr_tst {
|
||||
@Before public void init() {fxt.Reset();} private Xol_num_grp_fmtr_fxt fxt = new Xol_num_grp_fmtr_fxt();
|
||||
@Test public void Num() {
|
||||
fxt.Test_fmt_regx("" , "");
|
||||
fxt.Test_fmt_regx("1" , "1");
|
||||
fxt.Test_fmt_regx("12" , "12");
|
||||
fxt.Test_fmt_regx("123" , "123");
|
||||
fxt.Test_fmt_regx("1234" , "1,234");
|
||||
fxt.Test_fmt_regx("12345" , "12,345");
|
||||
fxt.Test_fmt_regx("123456" , "123,456");
|
||||
fxt.Test_fmt_regx("1234567" , "1,234,567");
|
||||
fxt.Test_fmt_regx("1234567890" , "1,234,567,890");
|
||||
}
|
||||
@Test public void Dec() {
|
||||
fxt.Test_fmt_regx("1.9876" , "1.9876");
|
||||
fxt.Test_fmt_regx("1234.9876" , "1,234.9876");
|
||||
}
|
||||
@Test public void Neg() {
|
||||
fxt.Test_fmt_regx("-1234.5678" , "-1,234.5678");
|
||||
}
|
||||
@Test public void Char() {
|
||||
fxt.Test_fmt_regx("1,234" , "1,234");
|
||||
fxt.Test_fmt_regx("1a2345" , "1a2,345");
|
||||
fxt.Test_fmt_regx("1234a5678b2345c.3456d7890e3210.f5432", "1,234a5,678b2,345c.3456d7,890e3,210.f5,432");
|
||||
}
|
||||
}
|
||||
class Xol_num_grp_fmtr_fxt {
|
||||
private Xol_num_grp_fmtr grouper = new Xol_num_grp_fmtr();
|
||||
private Bry_bfr bfr = Bry_bfr_.New();
|
||||
public void Reset() {}
|
||||
public void Test_fmt_regx(String raw, String expd) {
|
||||
byte[] actl = grouper.Fmt_regx(bfr, Bry_.new_a7(raw));
|
||||
Tfds.Eq(expd, String_.new_u8(actl));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user