github.com/unigraph-dev/dgraph@v1.1.1-0.20200923154953-8b52b426f765/systest/_customtok/cidr/main_test.go (about) 1 /* 2 * Copyright 2017-2018 Dgraph Labs, Inc. and Contributors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package main 18 19 import ( 20 "reflect" 21 "testing" 22 ) 23 24 func TestTokens(t *testing.T) { 25 for _, test := range []struct { 26 input string 27 output []string 28 }{ 29 { 30 input: "55.21.81.100/32", 31 output: []string{ 32 "55.21.81.100/32", 33 "55.21.81.100/31", 34 "55.21.81.100/30", 35 "55.21.81.96/29", 36 "55.21.81.96/28", 37 "55.21.81.96/27", 38 "55.21.81.64/26", 39 "55.21.81.0/25", 40 "55.21.81.0/24", 41 "55.21.80.0/23", 42 "55.21.80.0/22", 43 "55.21.80.0/21", 44 "55.21.80.0/20", 45 "55.21.64.0/19", 46 "55.21.64.0/18", 47 "55.21.0.0/17", 48 "55.21.0.0/16", 49 "55.20.0.0/15", 50 "55.20.0.0/14", 51 "55.16.0.0/13", 52 "55.16.0.0/12", 53 "55.0.0.0/11", 54 "55.0.0.0/10", 55 "55.0.0.0/9", 56 "55.0.0.0/8", 57 "54.0.0.0/7", 58 "52.0.0.0/6", 59 "48.0.0.0/5", 60 "48.0.0.0/4", 61 "32.0.0.0/3", 62 "0.0.0.0/2", 63 "0.0.0.0/1", 64 }, 65 }, 66 { 67 input: "21.85.0.0/16", 68 output: []string{ 69 "21.85.0.0/16", 70 "21.84.0.0/15", 71 "21.84.0.0/14", 72 "21.80.0.0/13", 73 "21.80.0.0/12", 74 "21.64.0.0/11", 75 "21.64.0.0/10", 76 "21.0.0.0/9", 77 "21.0.0.0/8", 78 "20.0.0.0/7", 79 "20.0.0.0/6", 80 "16.0.0.0/5", 81 "16.0.0.0/4", 82 "0.0.0.0/3", 83 "0.0.0.0/2", 84 "0.0.0.0/1", 85 }, 86 }, 87 } { 88 got, err := Tokens(test.input) 89 if err != nil { 90 t.Error(err) 91 } 92 if !reflect.DeepEqual(got, test.output) { 93 t.Errorf("Got=%v Want=%v", got, test.output) 94 } 95 } 96 }