// Copyright 2015 The Gogs Authors. All rights reserved.
// Copyright 2018 Gitote. All rights reserved.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.

package markup_test

import (
	. "gitote/gitote/pkg/markup"
	"testing"

	. "github.com/smartystreets/goconvey/convey"
)

func Test_Sanitizer(t *testing.T) {
	NewSanitizer()
	Convey("Sanitize HTML string and bytes", t, func() {
		testCases := []string{
			// Regular
			`<a onblur="alert(secret)" href="http://www.google.com">Google</a>`, `<a href="http://www.google.com" rel="nofollow">Google</a>`,

			// Code highlighting class
			`<code class="random string"></code>`, `<code></code>`,
			`<code class="language-random ui tab active menu attached animating sidebar following bar center"></code>`, `<code></code>`,
			`<code class="language-go"></code>`, `<code class="language-go"></code>`,

			// Input checkbox
			`<input type="hidden">`, ``,
			`<input type="checkbox">`, `<input type="checkbox">`,
			`<input checked disabled autofocus>`, `<input checked="" disabled="">`,
		}

		for i := 0; i < len(testCases); i += 2 {
			So(Sanitize(testCases[i]), ShouldEqual, testCases[i+1])
			So(string(SanitizeBytes([]byte(testCases[i]))), ShouldEqual, testCases[i+1])
		}
	})
}
