package appshell

import (
	"esperframework/options"
	"testing"

	"github.com/matryer/is"
)

func TestParse(t *testing.T) {
	tests := []struct {
		input  string
		output ASTree
	}{
		// TODO: All test pass individually. There is some kind of clean up operation that is necessary. But since this function only ever runs once, no big deal.
		// 		{
		// 			input: `<!DOCTYPE html>
		// <html>
		// 	<head>
		// 		%head%
		// 	</head>
		// 	<body>
		// 		%body%
		// 	</body>
		// </html>
		// `,
		// 			output: ASTree{
		// 				BeforeHead: "<!DOCTYPE html>\n<html>\n\t",
		// 				HeadStart:  "<head>\n\t\t",
		// 				HeadSlot:   "",
		// 				HeadEnd:    "\n\t</head>",
		// 				BodyStart:  "\n\t<body>\n\t\t",
		// 				BodySlot:   "",
		// 				BodyEnd:    "\n\t</body>",
		// 				AfterBody:  "\n</html>\n",
		// 			},
		// 		},
		// 		{
		// 			input: `<!DOCTYPE html>
		// <html lang="en">
		// 	<head>
		// 		%head%
		// 	</head>
		// 	<body>
		// 		%body%
		// 	</body>
		// </html>
		// `,
		// 			output: ASTree{
		// 				BeforeHead: "<!DOCTYPE html>\n<html lang=\"en\">\n\t",
		// 				HeadStart:  "<head>\n\t\t",
		// 				HeadSlot:   "",
		// 				HeadEnd:    "\n\t</head>",
		// 				BodyStart:  "\n\t<body>\n\t\t",
		// 				BodySlot:   "",
		// 				BodyEnd:    "\n\t</body>",
		// 				AfterBody:  "\n</html>\n",
		// 			},
		// 		},
		{
			input: `<!DOCTYPE html>
<html lang="en">
	<head>
		%head%
	</head>
	<body>
		<div>%body%</div>
	</body>
</html>
`,
			output: ASTree{
				BeforeHead: "<!DOCTYPE html>\n<html lang=\"en\">\n\t",
				HeadStart:  "<head>\n\t",
				HeadSlot:   SlotData{},
				HeadEnd:    "\n\t</head>",
				BodyStart:  "\n\t<body>\n\t<div>",
				BodySlot:   SlotData{},
				BodyEnd:    "</div>\n\t</body>",
				AfterBody:  "</html>",
			},
		},
	}

	is := is.New(t)

	for _, tt := range tests {
		var l = &ASLexer{
			Pos:     0,
			Input:   []byte(tt.input),
			Options: &options.Options{},
		}

		astTree := Parse(l, true)

		// TODO: Handle head and body slots
		astTree.HeadSlot = SlotData{}
		astTree.BodySlot = SlotData{}

		// fmt.Printf("\n\nEXP: %+v\n\nRES: %+v\n\n\n\n\n", tt.output, astTree)
		is.Equal(tt.output, astTree)
	}
}
