Skip to content

Failing test cases #8

Description

@wolfgang42

These are the issues I found in my first five minutes trying to use this library. I've also written test cases suitable for pasting into pug_test.go, I hope this is helpful for you.

Summary:

  • Single quotes in attributes (div(id='foo')) cause parse error.
  • Block comments cause parse error.
  • Buffered comments (which should appear in the output), aren't.
  • Tag interpolation seems not to be implemented.
  • Certain kinds of if are converted into <if> tags.
func Test_Attribute_SingleQuote(t *testing.T) {
		res, err := run(`div(id='foo')`, nil)

		if err != nil {
				t.Fatal(err.Error())
		} else {
				expect(res, `<div id="foo"></div>`, t)
		}
}

func Test_UnbufferedComment(t *testing.T) {
		res, err := run(`
//- This is an unbuffered comment. It should not appear in the output.
		It is also a multiline comment. This line shouldn't appear either.
`, nil)

		if err != nil {
				t.Fatal(err.Error())
		} else {
				expect(res, ``, t)
		}
}

func Test_Comment(t *testing.T) {
		res, err := run(`// This is a comment`, nil)

		if err != nil {
				t.Fatal(err.Error())
		} else {
				expect(res, `<!-- This is a comment -->`, t)
		}
}

func Test_TagInterpolation(t *testing.T) {
		res, err := run(`p This text is #[strong important!]`, nil)

		if err != nil {
				t.Fatal(err.Error())
		} else {
				expect(res, `<p>This text is <strong>important!</strong></p>`, t)
		}
}

func Test_If(t *testing.T) {
	res, err := run(`
if Key == "foo"
	| foo
else
 | bar
if Key == 'foo'
	|baz
`, testStruct{Key: "foo"})

	if err != nil {
		t.Fatal(err.Error())
	} else {
		expect(res, `foobaz`, t)
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions