From 96b685b82f5466e36faa53de2f3cd35196376e60 Mon Sep 17 00:00:00 2001 From: Bill Neubauer Date: Fri, 5 Nov 2021 11:59:49 -0700 Subject: API implementation for the Normalize method. This method is used to help applications render diffs of input files against reference license docs. Normalize may need a few more tests based on what we learn from building diffs against it. As currently implemented, the contract is pretty simple resulting in simple tests, but I anticipate that may change. PiperOrigin-RevId: 407875955 --- v2/classifier_test.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'v2/classifier_test.go') diff --git a/v2/classifier_test.go b/v2/classifier_test.go index e4cab30..cb613e5 100644 --- a/v2/classifier_test.go +++ b/v2/classifier_test.go @@ -309,3 +309,37 @@ func TestLicenseName(t *testing.T) { }) } } + +func TestNormalize(t *testing.T) { + tests := []struct { + input string + want string + }{ + { + input: "Words With Extra Spaces are flattened out, preserving case", + want: "Words With Extra Spaces are flattened out preserving case", + }, + { + input: "", + want: "", + }, + { + input: " License ", + want: "License", + }, + } + for _, tt := range tests { + t.Run(tt.input, func(t *testing.T) { + c, err := classifier() + if err != nil { + t.Fatalf("couldn't instantiate standard Google classifier: %v", err) + } + + got := c.Normalize([]byte(tt.input)) + if diff := cmp.Diff(tt.want, string(got)); diff != "" { + t.Errorf("Unexpected result; diff %v", diff) + } + }) + } + +} -- cgit v1.2.3