GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — gitql/autocomplete_test.go at main · filhodanuvem/gitql Expand file tree/ Copy pathautocomplete_test.goMore file actions 260 lines (234 loc) · 5.37 KB / Copy pathautocomplete_test.goFile metadata and controls260 lines (234 loc) · 5.37 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 package main import ( "strings" "testing" ) func TestSuggestColumnsFromLatest(t *testing.T) { answer := []string{ "hash", "type", "date", "author", "author_email", "committer", "committer_email", "message", "full_message", "name", "full_name", } expected := createHashMap(answer) result := suggestColumnsFromLatest("hash,") for _, v := range result { if _, ok := expected[string(v)]; !ok { t.Errorf("expected 'hash', 'type', 'date', 'author', 'author_email', 'committer', 'committer_email', 'message', 'full_message', 'name', 'full_name' got %s", string(v)) } } } func TestRemoveDuplicates(t *testing.T) { words := [][]rune{ []rune("alpaca"), []rune("alpaca"), []rune("Code-Hex"), []rune("Hello"), []rune("Hello"), []rune("World"), } removeDuplicates(&words) if len(words) != 4 { t.Error("Failed to remove duplicates") } if string(words[0]) != "alpaca" { t.Errorf("expected alpaca, got %s", string(words[0])) } if string(words[1]) != "Code-Hex" { t.Errorf("expected Code-Hex, got %s", string(words[1])) } if string(words[2]) != "Hello" { t.Errorf("expected Hello, got %s", string(words[2])) } if string(words[3]) != "World" { t.Errorf("expected World, got %s", string(words[3])) } } func TestIsContained(t *testing.T) { idx, ok := isContained("Code-Hex", []string{"cloudson", "luizperes", "Code-Hex"}) if !ok { t.Error("Failed to invoke `isContained`") } if idx != 2 { t.Errorf("expected %d, got %d", 2, idx) } } func TestGetPartsFromSlice(t *testing.T) { gotSlice := getPartsFromSlice("luizperes", []string{"cloudson", "luizperes", "Code-Hex"}) if len(gotSlice) != 2 { t.Error("Failed to invoke `getPartsFromSlice`") } if string(gotSlice[0]) != "cloudson" { t.Errorf("expected cloudson, got %s", string(gotSlice[0])) } if string(gotSlice[1]) != "Code-Hex" { t.Errorf("expected Code-Hex, got %s", string(gotSlice[1])) } notSlice := getPartsFromSlice("gopher", []string{"cloudson", "luizperes", "Code-Hex"}) if len(notSlice) != 0 { t.Error("Failed to invoke `getPartsFromSlice`") } } func TestSuggestQuery(t *testing.T) { // gitql> [tab // expected: select pattern1 := [][]rune{ []rune(""), } assertSuggestsQuery(t, pattern1, []string{"select"}) // gitql> select [tab // expected: *, name, url, push_url, owner, full_name, hash, date, author, // author_email, committer, committer_email, message, full_message, type pattern2 := [][]rune{ []rune("select"), []rune(""), } assertSuggestsQuery(t, pattern2, []string{ "distinct", "*", "name", "url", "push_url", "owner", "full_name", "hash", "date", "author", "author_email", "committer", "committer_email", "message", "full_message", "type", }) // gitql> select name [tab // expected: select, from, where, order, by, or, and, limit, in, asc, desc pattern3 := [][]rune{ []rune("select"), []rune("name"), []rune(""), } assertSuggestsQuery(t, pattern3, []string{ "select", "from", "where", "order", "by", "or", "and", "limit", "in", "asc", "desc", }) // gitql> select name, [tab // expected: full_name, type, hash, url, push_url, owner pattern4 := [][]rune{ []rune("select"), []rune("name,"), []rune(""), } assertSuggestsQuery(t, pattern4, []string{ "full_name", "type", "hash", "url", "push_url", "owner", }) // gitql> select * from [tab // expected: tags, branches, commits, refs pattern5 := [][]rune{ []rune("select"), []rune("*"), []rune("from"), []rune(""), } assertSuggestsQuery(t, pattern5, []string{ "tags", "branches", "commits", "refs", }) // gitql> select name from refs where [tab // expected: name, url, push_url, owner pattern6 := [][]rune{ []rune("select"), []rune("name"), []rune("from"), []rune("refs"), []rune("where"), []rune(""), } assertSuggestsQuery(t, pattern6, []string{"name", "full_name", "type", "hash"}) // gitql> select committer from commits where committer = "K" and [tab // expected: hash, date, author, author_email, committer, committer_email, message, full_message pattern7 := [][]rune{ []rune("select"), []rune("committer"), []rune("from"), []rune("commits"), []rune("where"), []rune("committer"), []rune("="), []rune(`"K"`), []rune("and"), []rune(""), } assertSuggestsQuery(t, pattern7, []string{ "hash", "date", "author", "author_email", "committer", "committer_email", "message", "full_message", }) // gitql> select committer from commits where committer = "k" order [tab // expected: by pattern8 := [][]rune{ []rune("select"), []rune("committer"), []rune("from"), []rune("commits"), []rune("where"), []rune("committer"), []rune("="), []rune(`"K"`), []rune("order"), []rune(""), } assertSuggestsQuery(t, pattern8, []string{"by"}) } // tiny tools func assertSuggestsQuery(t *testing.T, inputs [][]rune, expected []string) { result := suggestQuery(inputs, len(inputs[len(inputs)-1])) expectedHash := createHashMap(expected) for _, v := range result { _, ok := expectedHash[string(v)] if !ok { t.Errorf("expected: (%s), got: %s", strings.Join(expected, ", "), string(v)) break } } } func createHashMap(s []string) map[string]bool { h := make(map[string]bool, len(s)) for _, key := range s { h[key] = true } return h } func assertSuggests(t *testing.T, expected string, got string) { if expected != got { t.Errorf("expected %s, got %s", expected, got) } } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |