]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/go/arrow/_tools/tmpl/main_test.go
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / go / arrow / _tools / tmpl / main_test.go
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16
17 package main
18
19 import (
20 "testing"
21 )
22
23 func TestStripComments(t *testing.T) {
24 tests := []struct {
25 name string
26 in string
27 exp string
28 }{
29 {name: "none", in: `[1,2,3]`, exp: `[1,2,3]`},
30 {name: "single-line, line comment at end", in: `[1,2,3] // foo bar`, exp: `[1,2,3] `},
31 {name: "single-line, block comment at end", in: `[1,2,3] /* foo bar */ `, exp: `[1,2,3] `},
32 {name: "single-line, block comment at end", in: `[1,2,3] /* /* // */`, exp: `[1,2,3] `},
33 {name: "single-line, block comment in middle", in: `[1,/* foo bar */2,3]`, exp: `[1,2,3]`},
34 {name: "single-line, block comment in string", in: `[1,"/* foo bar */"]`, exp: `[1,"/* foo bar */"]`},
35 {name: "single-line, malformed block comment", in: `[1,2,/*]`, exp: `[1,2,/*]`},
36 {name: "single-line, malformed JSON", in: `[1,2,/]`, exp: `[1,2,/]`},
37
38 {
39 name: "multi-line",
40 in: `[
41 1,
42 2,
43 3
44 ]`,
45 exp: `[
46 1,
47 2,
48 3
49 ]`,
50 },
51 {
52 name: "multi-line, multiple line comments",
53 in: `[ // foo
54 1, // bar
55 2,
56 3
57 ] // fit`,
58 exp: `[
59 1,
60 2,
61 3
62 ] `,
63 },
64 }
65 for _, test := range tests {
66 t.Run(test.name, func(t *testing.T) {
67 got := string(StripComments([]byte(test.in)))
68 if got != test.exp {
69 t.Errorf("got:\n%s\nexp:\n%s", got, test.exp)
70 }
71 })
72 }
73 }