github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/cmd/docgen/extract/extract_test.go (about) 1 // Copyright 2017 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 package extract 11 12 import ( 13 "fmt" 14 "strings" 15 "testing" 16 ) 17 18 func TestSplitGroup(t *testing.T) { 19 g, err := ParseGrammar(strings.NewReader(` 20 a ::= 21 'A' b 22 23 b ::= 24 c 25 | b ',' c 26 27 c ::= 28 'B' 29 | 'C' 30 `)) 31 if err != nil { 32 t.Fatal(err) 33 } 34 if err := g.Inline("b", "c"); err != nil { 35 t.Fatal(err) 36 } 37 b, err := g.ExtractProduction("a", true, false, nil, nil) 38 if err != nil { 39 t.Fatal(err) 40 } 41 fmt.Println(string(b)) 42 } 43 44 func TestSplitOpt(t *testing.T) { 45 g, err := ParseGrammar(strings.NewReader(` 46 a ::= 47 'A' b 48 49 b ::= 50 'B' 51 | 52 `)) 53 if err != nil { 54 t.Fatal(err) 55 } 56 if err := g.Inline("b"); err != nil { 57 t.Fatal(err) 58 } 59 b, err := g.ExtractProduction("a", true, false, nil, nil) 60 if err != nil { 61 t.Fatal(err) 62 } 63 fmt.Println(string(b)) 64 }