package inliner import ( "fmt" "testing" ) // Simple rule inlining with two declarations func TestInliner(t *testing.T) { input := `

Inline me please!

` expectedOutput := `

Inline me please!

` output, err := Inline(input) if err != nil { t.Fatal("Failed to inline html:", err) } if output != expectedOutput { t.Fatal(fmt.Sprintf("CSS inliner error\nExpected:\n\"%s\"\nGot:\n\"%s\"", expectedOutput, output)) } } // Already inlined style has more priority than

Inline me please!

` expectedOutput := `

Inline me please!

` output, err := Inline(input) if err != nil { t.Fatal("Failed to inline html:", err) } if output != expectedOutput { t.Fatal(fmt.Sprintf("CSS inliner error\nExpected:\n\"%s\"\nGot:\n\"%s\"", expectedOutput, output)) } } // !important has highest priority func TestImportantPriority(t *testing.T) { input := `

Inline me please!

` expectedOutput := `

Inline me please!

` output, err := Inline(input) if err != nil { t.Fatal("Failed to inline html:", err) } if output != expectedOutput { t.Fatal(fmt.Sprintf("CSS inliner error\nExpected:\n\"%s\"\nGot:\n\"%s\"", expectedOutput, output)) } } // Pseudo-class selectors can't be inlined func TestNotInlinable(t *testing.T) { input := `

Superbe website

` expectedOutput := `

Superbe website

` output, err := Inline(input) if err != nil { t.Fatal("Failed to inline html:", err) } if output != expectedOutput { t.Fatal(fmt.Sprintf("CSS inliner error\nExpected:\n\"%s\"\nGot:\n\"%s\"", expectedOutput, output)) } } // Some styles causes insertion of additional element attributes func TestStyleToAttr(t *testing.T) { input := `

test

test

test

test

test
test

test
test
` expectedOutput := `

test

test

test

test

test
test

test
test
` output, err := Inline(input) if err != nil { t.Fatal("Failed to inline html:", err) } if output != expectedOutput { t.Fatal(fmt.Sprintf("CSS inliner error\nExpected:\n\"%s\"\nGot:\n\"%s\"", expectedOutput, output)) } }