github.com/googleapis/api-linter@v1.65.2/rules/aip0192/no_html_test.go (about) 1 // Copyright 2019 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package aip0192 16 17 import ( 18 "strings" 19 "testing" 20 21 "github.com/googleapis/api-linter/rules/internal/testutils" 22 ) 23 24 func TestNoHTML(t *testing.T) { 25 rawHTMLProblem := testutils.Problems{{Message: "must not include raw HTML"}} 26 noProblems := testutils.Problems{} 27 28 for _, test := range []struct { 29 name string 30 comment string 31 problems testutils.Problems 32 }{ 33 {"Valid", "It is **great!**", noProblems}, 34 {"ValidMath", "x < 10", noProblems}, 35 {"ValidMoreMath", "x < 10 > y", noProblems}, 36 {"ValidAngleBracketPlaceholders", "Format: http://<server>/<path>", noProblems}, 37 {"ValidComplexTag", `<img src="https://foo.bar/mickey" />`, noProblems}, 38 {"InvalidBold", "It is <b>great!</b>", rawHTMLProblem}, 39 {"InvalidCode", "This is <code>code font</code>.", rawHTMLProblem}, 40 {"InvalidBreak", "This spans<br />two lines.", rawHTMLProblem}, 41 {"IntentionalFalseNegativeInnerSpace", "Something < b > bold < /b >", noProblems}, 42 } { 43 t.Run(test.name, func(t *testing.T) { 44 f := testutils.ParseProto3String(t, strings.ReplaceAll(` 45 // A foo. {{.Comment}} 46 message Foo {} 47 `, "{{.Comment}}", test.comment)) 48 message := f.GetMessageTypes()[0] 49 if diff := test.problems.SetDescriptor(message).Diff(noHTML.Lint(f)); diff != "" { 50 t.Errorf(diff) 51 } 52 }) 53 } 54 }