1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-09-30 07:20:52 +00:00
gnosygnu_xowa/400_xowa/tst/gplx/xowa/htmls/minifys/XoCssMinTest.java

104 lines
4.9 KiB
Java
Raw Normal View History

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);
}
}