mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
TemplateStyles: Add XoCssMin from @desb42 [#704]
This commit is contained in:
27
400_xowa/tst/gplx/langs/javascripts/JsString_Test.java
Normal file
27
400_xowa/tst/gplx/langs/javascripts/JsString_Test.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package gplx.langs.javascripts;
|
||||
|
||||
import gplx.core.tests.Gftest;
|
||||
import org.junit.Test;
|
||||
|
||||
public class JsString_Test {
|
||||
private final JsString_Tstr tstr = new JsString_Tstr();
|
||||
@Test public void slice() {
|
||||
tstr.Test_slice("bgn.positive.basic", "bc" , "abc", 1);
|
||||
tstr.Test_slice("bgn.positive.large", "" , "abc", 4);
|
||||
tstr.Test_slice("bgn.negative.basic", "c" , "abc", -1);
|
||||
tstr.Test_slice("bgn.negative.large", "abc", "abc", -4);
|
||||
tstr.Test_slice("end.positive.basic", "b" , "abc", 1, 2);
|
||||
tstr.Test_slice("end.positive.eos" , "bc" , "abc", 1, 3);
|
||||
tstr.Test_slice("end.positive.large", "bc" , "abc", 1, 4);
|
||||
tstr.Test_slice("end.negative.basic", "b" , "abc", 1, -1);
|
||||
tstr.Test_slice("end.negative.large", "" , "abc", 1, -4);
|
||||
}
|
||||
}
|
||||
class JsString_Tstr {
|
||||
public void Test_slice(String note, String expd, String src, int bgn) {
|
||||
Gftest.Eq__str(expd, JsString_.slice(src, bgn), note);
|
||||
}
|
||||
public void Test_slice(String note, String expd, String src, int bgn, int end) {
|
||||
Gftest.Eq__str(expd, JsString_.slice(src, bgn, end), note);
|
||||
}
|
||||
}
|
||||
103
400_xowa/tst/gplx/xowa/htmls/minifys/XoCssMinTest.java
Normal file
103
400_xowa/tst/gplx/xowa/htmls/minifys/XoCssMinTest.java
Normal file
@@ -0,0 +1,103 @@
|
||||
package gplx.xowa.htmls.minifys;
|
||||
|
||||
import gplx.core.tests.Gftest;
|
||||
import gplx.core.tooling.dataCollectors.GfoDataCollectorMgr;
|
||||
import gplx.core.tooling.asserts.TestAssert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class XoCssMinTest {
|
||||
private final XoCssMinTstr tstr = new XoCssMinTstr();
|
||||
// NOTE: can pull more tests from https://github.com/yui/yuicompressor/tree/master/tests
|
||||
@Test public void extractDataUrls() {
|
||||
tstr.Test("extractDataUrls.basic" // all 3 types: `'`, `"`, ``
|
||||
, "url('data:a1') url(\"data:a2\") url(data:a3)"
|
||||
, "url('data:a1') url(\"data:a2\") url(data:a3)"
|
||||
, new TestAssert.Grp("extractDataUrls"
|
||||
, new TestAssert.ListEq("preservedTokens", "'data:a1'", "\"data:a2\"", "data:a3")
|
||||
, new TestAssert.StringEq("css", "url(___YUICSSMIN_PRESERVED_TOKEN_0___) url(___YUICSSMIN_PRESERVED_TOKEN_1___) url(___YUICSSMIN_PRESERVED_TOKEN_2___)")
|
||||
)
|
||||
);
|
||||
|
||||
tstr.Test("extractDataUrls.whitespace"
|
||||
, "url( 'data:a1 ' ) "
|
||||
, "url('data:a1')"
|
||||
, new TestAssert.Grp("extractDataUrls"
|
||||
, new TestAssert.ListEq("preservedTokens", "'data:a1'")
|
||||
, new TestAssert.StringEq("css", "url(___YUICSSMIN_PRESERVED_TOKEN_0___) ")
|
||||
)
|
||||
);
|
||||
|
||||
tstr.Test("extractDataUrls.escapedTerminator"
|
||||
, "url('data:a\\')bc')"
|
||||
, "url('data:a\\')bc')"
|
||||
, new TestAssert.Grp("extractDataUrls"
|
||||
, new TestAssert.ListEq("preservedTokens", "'data:a\\')bc'")
|
||||
, new TestAssert.StringEq("css", "url(___YUICSSMIN_PRESERVED_TOKEN_0___)")
|
||||
)
|
||||
);
|
||||
}
|
||||
@Test public void comments() {
|
||||
tstr.Test("collectComments.basic"
|
||||
, "a /* b */ c /* d */ e"
|
||||
, "a c e"
|
||||
, new TestAssert.Grp("collectComments"
|
||||
, new TestAssert.ListEq("comments", " b ", " d ")
|
||||
, new TestAssert.StringEq("css", "a /*___YUICSSMIN_PRESERVE_CANDIDATE_COMMENT_0___*/ c /*___YUICSSMIN_PRESERVE_CANDIDATE_COMMENT_1___*/ e")
|
||||
)
|
||||
);
|
||||
}
|
||||
@Test public void rgb() {
|
||||
tstr.Test("rgb.basic" ,"rgb (128,128,128)", "#808080");
|
||||
tstr.Test("rgb.casing" ,"RgB (128,128,128)", "#808080");
|
||||
}
|
||||
@Test public void borders() {
|
||||
tstr.Test("borders.basic" , "border:none;" , "border:0;");
|
||||
tstr.Test("borders.background" , "background:none;", "background:0;");
|
||||
tstr.Test("borders.casing" , "bOrDeR:NoNe;" , "border:0;");
|
||||
tstr.Test("borders.close-brace", "{border:none}" , "{border:0}");
|
||||
}
|
||||
@Test public void background() {
|
||||
tstr.Test("background.basic" ,"background-position:0;" , "background-position:0 0;");
|
||||
tstr.Test("background.ms-transform","ms-transform-origin:0;" , "ms-transform-origin:0 0;");
|
||||
tstr.Test("background.casing" ,"Background-Position:0;" , "background-position:0 0;");
|
||||
tstr.Test("background.close-brace" ,"{background-position:0}", "{background-position:0 0}");
|
||||
}
|
||||
@Test public void pseudo() {
|
||||
tstr.Test("swapPseudo.caret"
|
||||
, "abc ^ class:val { xyz"
|
||||
, "abc ^ class:val{xyz"
|
||||
, new TestAssert.Grp("swapPseudo"
|
||||
, new TestAssert.StringEq("css", "abc ^ class___YUICSSMIN_PSEUDOCLASSCOLON___val { xyz")
|
||||
)
|
||||
);
|
||||
|
||||
tstr.Test("swapPseudo.brace"
|
||||
, "abc } class:val { xyz"
|
||||
, "abc}class:val{xyz"
|
||||
, new TestAssert.Grp("swapPseudo"
|
||||
, new TestAssert.StringEq("css", "abc } class___YUICSSMIN_PSEUDOCLASSCOLON___val { xyz")
|
||||
)
|
||||
);
|
||||
}
|
||||
@Test public void compressHex() {
|
||||
tstr.Test("compressHex.basic" ,"( #aa1199)" , "(#a19)");
|
||||
tstr.Test("compressHex.case" ,"( #ABCDEF)" , "(#abcdef)");
|
||||
tstr.Test("compressHex.skip" ,"color=#ffffff"); // surprisingly, this doesn't compress due to ([^"'=\s])
|
||||
tstr.Test("compressHex.chromaExample","filter:chroma(color=\"#FFFFFF\");");
|
||||
}
|
||||
}
|
||||
class XoCssMinTstr {
|
||||
private final XoCssMin min = new XoCssMin();
|
||||
private GfoDataCollectorMgr dataCollectorMgr = new GfoDataCollectorMgr();
|
||||
public void Mode_(int v) {mode = v;} private int mode = XoCssMin.MODE_NODEJS | XoCssMin.MODE_YCSS_MIN;
|
||||
public void Test(String note, String orig, TestAssert.Grp... expdRules) {Test(note, orig, orig, expdRules);}
|
||||
public void Test(String note, String orig, String expd, TestAssert.Grp... expdRules) {
|
||||
if (expdRules != null)
|
||||
min.DataCollectorMgr_(dataCollectorMgr);
|
||||
String actl = min.cssmin(orig, -1, mode);
|
||||
if (expdRules != null) {
|
||||
TestAssert.Test(note, dataCollectorMgr, expdRules);
|
||||
}
|
||||
Gftest.Eq__str(expd, actl, note);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user