github.com/cayleygraph/cayley@v0.7.7/internal/repl/repl_test.go (about)

     1  // Copyright 2014 The Cayley Authors. All rights reserved.
     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  //     http://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 repl
    16  
    17  import (
    18  	"testing"
    19  )
    20  
    21  var testSplitLines = []struct {
    22  	line              string
    23  	expectedCommand   string
    24  	expectedArguments string
    25  	err               error
    26  }{
    27  	{
    28  		line:              ":a arg1 arg2 arg3 .",
    29  		expectedCommand:   ":a",
    30  		expectedArguments: " arg1 arg2 arg3 .",
    31  	},
    32  	{
    33  		line:              ":debug t",
    34  		expectedCommand:   ":debug",
    35  		expectedArguments: " t",
    36  	},
    37  	{
    38  		line: "",
    39  		// expectedCommand is nil
    40  		// expectedArguments is nil
    41  	},
    42  	{
    43  		line:              `:d <http://one.example/subject1> <http://one.example/predicate1> <http://one.example/object1> . # comments here`,
    44  		expectedCommand:   ":d",
    45  		expectedArguments: ` <http://one.example/subject1> <http://one.example/predicate1> <http://one.example/object1> . # comments here`,
    46  	},
    47  	{
    48  		line:              `  :a  subject  "predicate with spaces" object  . `,
    49  		expectedCommand:   ":a",
    50  		expectedArguments: `  subject  "predicate with spaces" object  .`,
    51  	},
    52  }
    53  
    54  func TestSplitLines(t *testing.T) {
    55  	for _, testcase := range testSplitLines {
    56  		command, arguments := splitLine(testcase.line)
    57  
    58  		if testcase.expectedCommand != command {
    59  			t.Errorf("Error splitting lines: got: %v expected: %v", command, testcase.expectedCommand)
    60  		}
    61  
    62  		if testcase.expectedArguments != arguments {
    63  			t.Errorf("Error splitting lines: got: %v expected: %v", arguments, testcase.expectedArguments)
    64  		}
    65  	}
    66  }