diff options
author | Bill Neubauer <wcn@google.com> | 2021-11-05 11:59:49 -0700 |
---|---|---|
committer | Bill Neubauer <wcn@google.com> | 2022-03-16 15:34:44 -0700 |
commit | 96b685b82f5466e36faa53de2f3cd35196376e60 (patch) | |
tree | 6865558a386de0e71f6a84a2bfe4861ef90002c4 /v2/classifier_test.go | |
parent | a856fae32bc46162436e1bfbc3cbcb0f2b6a9ef3 (diff) | |
download | licenseclassifier-96b685b82f5466e36faa53de2f3cd35196376e60.tar.gz |
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
Diffstat (limited to 'v2/classifier_test.go')
-rw-r--r-- | v2/classifier_test.go | 34 |
1 files changed, 34 insertions, 0 deletions
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) + } + }) + } + +} |