z811_useCase_GfmlIoSql_tst.java 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. XOWA: the XOWA Offline Wiki Application
  3. Copyright (C) 2012-2017 gnosygnu@gmail.com
  4. XOWA is licensed under the terms of the General Public License (GPL) Version 3,
  5. or alternatively under the terms of the Apache License Version 2.0.
  6. You may use XOWA according to either of these licenses as is most appropriate
  7. for your project on a case-by-case basis.
  8. The terms of each license can be found in the source code repository:
  9. GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
  10. Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
  11. */
  12. package gplx.gfml; import gplx.*;
  13. import org.junit.*;
  14. public class z811_useCase_GfmlIoSql_tst {
  15. @Test public void Basic() {
  16. tst_Doc("fld1=val1", nde_("fld").Atrs_add_("word", "fld1").Atrs_add_("op", "=").Atrs_add_("word", "val1"));
  17. tst_Doc("fld1 = val1", nde_("fld").Atrs_add_("word", "fld1").Atrs_add_("op", "=").Atrs_add_("word", "val1"));
  18. tst_Doc("fld1='val1'", nde_("fld").Atrs_add_("word", "fld1").Atrs_add_("op", "=").Atrs_add_("word", "val1"));
  19. tst_Doc("fld1='val 1'", nde_("fld").Atrs_add_("word", "fld1").Atrs_add_("op", "=").Atrs_add_("word", "val 1"));
  20. }
  21. @Test public void Basic2() {
  22. tst_Doc("1=1 OR 2=2", nde_("fld").Atrs_add_("word", "1").Atrs_add_("op", "=").Atrs_add_("word", "1")
  23. .Atrs_add_("word", "OR")
  24. .Atrs_add_("word", "2").Atrs_add_("op", "=").Atrs_add_("word", "2")
  25. );
  26. tst_Doc("(1=1)", nde_("fld").Atrs_add_("op", "(").Atrs_add_("word", "1").Atrs_add_("op", "=").Atrs_add_("word", "1")
  27. .Atrs_add_("op", ")")
  28. );
  29. }
  30. void tst_Doc(String raw, GfmlNdeWrapper expd) {
  31. GfmlDoc doc = SqlDoc.XtoDoc(raw);
  32. GfmlNde actl = (GfmlNde)doc.RootNde();
  33. Tfds.Eq_ary_str(To_str(expd.Nde()), To_str(actl));
  34. }
  35. String[] To_str(GfmlNde nde) {
  36. List_adp list = List_adp_.New();
  37. for (int i = 0; i < nde.SubObjs_Count(); i++) {
  38. GfmlAtr atr = (GfmlAtr)nde.SubObjs_GetAt(i);
  39. list.Add(atr.Key() + "=" + atr.DatTkn().Raw());
  40. }
  41. return list.To_str_ary();
  42. }
  43. GfmlNdeWrapper nde_(String name) {return GfmlNdeWrapper.new_().Name_(name);}
  44. }