How to use Close method of main Package

Best Syzkaller code snippet using main.Close

lexer_test.go

Source:lexer_test.go Github

copy

Full Screen

...13 next := Lex(input).NextToken14 assert.Equal(token.Token{token.IntKeywordToken, "int"}, next())15 assert.Equal(token.Token{token.IdentifierToken, "main"}, next())16 assert.Equal(token.Token{token.OpenParenthesisToken, "("}, next())17 assert.Equal(token.Token{token.CloseParenthesisToken, ")"}, next())18 assert.Equal(token.Token{token.OpenBraceToken, "{"}, next())19 assert.Equal(token.Token{token.ReturnKeywordToken, "return"}, next())20 assert.Equal(token.Token{token.NumberToken, "100"}, next())21 assert.Equal(token.Token{token.SemicolonToken, ";"}, next())22 assert.Equal(token.Token{token.CloseBraceToken, "}"}, next())23 assert.Equal(token.EofToken, next().Type)24}25func TestLexNewlines(t *testing.T) {26 assert := assert.New(t)27 input := `28int 29main30( 31)32{33return34;35}`36 next := Lex(input).NextToken37 assert.Equal(token.Token{token.IntKeywordToken, "int"}, next())38 assert.Equal(token.Token{token.IdentifierToken, "main"}, next())39 assert.Equal(token.Token{token.OpenParenthesisToken, "("}, next())40 assert.Equal(token.Token{token.CloseParenthesisToken, ")"}, next())41 assert.Equal(token.Token{token.OpenBraceToken, "{"}, next())42 assert.Equal(token.Token{token.ReturnKeywordToken, "return"}, next())43 assert.Equal(token.Token{token.NumberToken, "0"}, next())44 assert.Equal(token.Token{token.SemicolonToken, ";"}, next())45 assert.Equal(token.Token{token.CloseBraceToken, "}"}, next())46 assert.Equal(token.EofToken, next().Type)47}48func TestLexNoNewlines(t *testing.T) {49 assert := assert.New(t)50 input := `int main(){return 0;}`51 next := Lex(input).NextToken52 assert.Equal(token.Token{token.IntKeywordToken, "int"}, next())53 assert.Equal(token.Token{token.IdentifierToken, "main"}, next())54 assert.Equal(token.Token{token.OpenParenthesisToken, "("}, next())55 assert.Equal(token.Token{token.CloseParenthesisToken, ")"}, next())56 assert.Equal(token.Token{token.OpenBraceToken, "{"}, next())57 assert.Equal(token.Token{token.ReturnKeywordToken, "return"}, next())58 assert.Equal(token.Token{token.NumberToken, "0"}, next())59 assert.Equal(token.Token{token.SemicolonToken, ";"}, next())60 assert.Equal(token.Token{token.CloseBraceToken, "}"}, next())61 assert.Equal(token.EofToken, next().Type)62}63func TestLexReturn0(t *testing.T) {64 assert := assert.New(t)65 input := `int main() {66 return 0;67}`68 next := Lex(input).NextToken69 assert.Equal(token.Token{token.IntKeywordToken, "int"}, next())70 assert.Equal(token.Token{token.IdentifierToken, "main"}, next())71 assert.Equal(token.Token{token.OpenParenthesisToken, "("}, next())72 assert.Equal(token.Token{token.CloseParenthesisToken, ")"}, next())73 assert.Equal(token.Token{token.OpenBraceToken, "{"}, next())74 assert.Equal(token.Token{token.ReturnKeywordToken, "return"}, next())75 assert.Equal(token.Token{token.NumberToken, "0"}, next())76 assert.Equal(token.Token{token.SemicolonToken, ";"}, next())77 assert.Equal(token.Token{token.CloseBraceToken, "}"}, next())78 assert.Equal(token.EofToken, next().Type)79}80func TestLexReturn2(t *testing.T) {81 assert := assert.New(t)82 input := `int main() {83 return 2;84}`85 next := Lex(input).NextToken86 assert.Equal(token.Token{token.IntKeywordToken, "int"}, next())87 assert.Equal(token.Token{token.IdentifierToken, "main"}, next())88 assert.Equal(token.Token{token.OpenParenthesisToken, "("}, next())89 assert.Equal(token.Token{token.CloseParenthesisToken, ")"}, next())90 assert.Equal(token.Token{token.OpenBraceToken, "{"}, next())91 assert.Equal(token.Token{token.ReturnKeywordToken, "return"}, next())92 assert.Equal(token.Token{token.NumberToken, "2"}, next())93 assert.Equal(token.Token{token.SemicolonToken, ";"}, next())94 assert.Equal(token.Token{token.CloseBraceToken, "}"}, next())95 assert.Equal(token.EofToken, next().Type)96}97func TestLexSpaces(t *testing.T) {98 assert := assert.New(t)99 input := ` int main ( ) { return 0 ; }`100 next := Lex(input).NextToken101 assert.Equal(token.Token{token.IntKeywordToken, "int"}, next())102 assert.Equal(token.Token{token.IdentifierToken, "main"}, next())103 assert.Equal(token.Token{token.OpenParenthesisToken, "("}, next())104 assert.Equal(token.Token{token.CloseParenthesisToken, ")"}, next())105 assert.Equal(token.Token{token.OpenBraceToken, "{"}, next())106 assert.Equal(token.Token{token.ReturnKeywordToken, "return"}, next())107 assert.Equal(token.Token{token.NumberToken, "0"}, next())108 assert.Equal(token.Token{token.SemicolonToken, ";"}, next())109 assert.Equal(token.Token{token.CloseBraceToken, "}"}, next())110 assert.Equal(token.EofToken, next().Type)111}112// Test inputs from github.com/nlsandler/write_a_c_compiler/stage_1/invalid113func TestLexMissingParen(t *testing.T) {114 assert := assert.New(t)115 input := `int main( {116 return 0;117}`118 next := Lex(input).NextToken119 assert.Equal(token.Token{token.IntKeywordToken, "int"}, next())120 assert.Equal(token.Token{token.IdentifierToken, "main"}, next())121 assert.Equal(token.Token{token.OpenParenthesisToken, "("}, next())122 assert.Equal(token.Token{token.OpenBraceToken, "{"}, next())123 assert.Equal(token.Token{token.ReturnKeywordToken, "return"}, next())124 assert.Equal(token.Token{token.NumberToken, "0"}, next())125 assert.Equal(token.Token{token.SemicolonToken, ";"}, next())126 assert.Equal(token.Token{token.CloseBraceToken, "}"}, next())127 assert.Equal(token.EofToken, next().Type)128}129func TestLexMissingRetval(t *testing.T) {130 assert := assert.New(t)131 input := `int main() {132 return;133}`134 next := Lex(input).NextToken135 assert.Equal(token.Token{token.IntKeywordToken, "int"}, next())136 assert.Equal(token.Token{token.IdentifierToken, "main"}, next())137 assert.Equal(token.Token{token.OpenParenthesisToken, "("}, next())138 assert.Equal(token.Token{token.CloseParenthesisToken, ")"}, next())139 assert.Equal(token.Token{token.OpenBraceToken, "{"}, next())140 assert.Equal(token.Token{token.ReturnKeywordToken, "return"}, next())141 assert.Equal(token.Token{token.SemicolonToken, ";"}, next())142 assert.Equal(token.Token{token.CloseBraceToken, "}"}, next())143 assert.Equal(token.EofToken, next().Type)144}145func TestLexNoBrace(t *testing.T) {146 assert := assert.New(t)147 input := `int main {148 return 0;149`150 next := Lex(input).NextToken151 assert.Equal(token.Token{token.IntKeywordToken, "int"}, next())152 assert.Equal(token.Token{token.IdentifierToken, "main"}, next())153 assert.Equal(token.Token{token.OpenBraceToken, "{"}, next())154 assert.Equal(token.Token{token.ReturnKeywordToken, "return"}, next())155 assert.Equal(token.Token{token.NumberToken, "0"}, next())156 assert.Equal(token.Token{token.SemicolonToken, ";"}, next())157 assert.Equal(token.EofToken, next().Type)158}159func TestLexNoSemicolon(t *testing.T) {160 assert := assert.New(t)161 input := `int main {162 return 0163}`164 next := Lex(input).NextToken165 assert.Equal(token.Token{token.IntKeywordToken, "int"}, next())166 assert.Equal(token.Token{token.IdentifierToken, "main"}, next())167 assert.Equal(token.Token{token.OpenBraceToken, "{"}, next())168 assert.Equal(token.Token{token.ReturnKeywordToken, "return"}, next())169 assert.Equal(token.Token{token.NumberToken, "0"}, next())170 assert.Equal(token.Token{token.CloseBraceToken, "}"}, next())171 assert.Equal(token.EofToken, next().Type)172}173func TestLexNoSpace(t *testing.T) {174 assert := assert.New(t)175 input := `int main() {176 return0;177}`178 next := Lex(input).NextToken179 assert.Equal(token.Token{token.IntKeywordToken, "int"}, next())180 assert.Equal(token.Token{token.IdentifierToken, "main"}, next())181 assert.Equal(token.Token{token.OpenParenthesisToken, "("}, next())182 assert.Equal(token.Token{token.CloseParenthesisToken, ")"}, next())183 assert.Equal(token.Token{token.OpenBraceToken, "{"}, next())184 assert.Equal(token.Token{token.IdentifierToken, "return0"}, next())185 assert.Equal(token.Token{token.SemicolonToken, ";"}, next())186 assert.Equal(token.Token{token.CloseBraceToken, "}"}, next())187 assert.Equal(token.EofToken, next().Type)188}189func TestLexWrongCase(t *testing.T) {190 assert := assert.New(t)191 input := `int main() {192 RETURN 0;193}`194 next := Lex(input).NextToken195 assert.Equal(token.Token{token.IntKeywordToken, "int"}, next())196 assert.Equal(token.Token{token.IdentifierToken, "main"}, next())197 assert.Equal(token.Token{token.OpenParenthesisToken, "("}, next())198 assert.Equal(token.Token{token.CloseParenthesisToken, ")"}, next())199 assert.Equal(token.Token{token.OpenBraceToken, "{"}, next())200 assert.Equal(token.Token{token.IdentifierToken, "RETURN"}, next())201 assert.Equal(token.Token{token.NumberToken, "0"}, next())202 assert.Equal(token.Token{token.SemicolonToken, ";"}, next())203 assert.Equal(token.Token{token.CloseBraceToken, "}"}, next())204 assert.Equal(token.EofToken, next().Type)205}206// Test inputs from github.com/nlsandler/write_a_c_compiler/stage_2/valid207func TestLexBitwise(t *testing.T) {208 assert := assert.New(t)209 input := `int main() {210 return !12;211}`212 next := Lex(input).NextToken213 assert.Equal(token.Token{token.IntKeywordToken, "int"}, next())214 assert.Equal(token.Token{token.IdentifierToken, "main"}, next())215 assert.Equal(token.Token{token.OpenParenthesisToken, "("}, next())216 assert.Equal(token.Token{token.CloseParenthesisToken, ")"}, next())217 assert.Equal(token.Token{token.OpenBraceToken, "{"}, next())218 assert.Equal(token.Token{token.ReturnKeywordToken, "return"}, next())219 assert.Equal(token.Token{token.LogicalNegationToken, "!"}, next())220 assert.Equal(token.Token{token.NumberToken, "12"}, next())221 assert.Equal(token.Token{token.SemicolonToken, ";"}, next())222 assert.Equal(token.Token{token.CloseBraceToken, "}"}, next())223 assert.Equal(token.EofToken, next().Type)224}225func TestLexBitwiseZero(t *testing.T) {226 assert := assert.New(t)227 input := `int main() {228 return ~0;229}`230 next := Lex(input).NextToken231 assert.Equal(token.Token{token.IntKeywordToken, "int"}, next())232 assert.Equal(token.Token{token.IdentifierToken, "main"}, next())233 assert.Equal(token.Token{token.OpenParenthesisToken, "("}, next())234 assert.Equal(token.Token{token.CloseParenthesisToken, ")"}, next())235 assert.Equal(token.Token{token.OpenBraceToken, "{"}, next())236 assert.Equal(token.Token{token.ReturnKeywordToken, "return"}, next())237 assert.Equal(token.Token{token.BitwiseComplementToken, "~"}, next())238 assert.Equal(token.Token{token.NumberToken, "0"}, next())239 assert.Equal(token.Token{token.SemicolonToken, ";"}, next())240 assert.Equal(token.Token{token.CloseBraceToken, "}"}, next())241 assert.Equal(token.EofToken, next().Type)242}243func TestLexNeg(t *testing.T) {244 assert := assert.New(t)245 input := `int main() {246 return -5;247}`248 next := Lex(input).NextToken249 assert.Equal(token.Token{token.IntKeywordToken, "int"}, next())250 assert.Equal(token.Token{token.IdentifierToken, "main"}, next())251 assert.Equal(token.Token{token.OpenParenthesisToken, "("}, next())252 assert.Equal(token.Token{token.CloseParenthesisToken, ")"}, next())253 assert.Equal(token.Token{token.OpenBraceToken, "{"}, next())254 assert.Equal(token.Token{token.ReturnKeywordToken, "return"}, next())255 assert.Equal(token.Token{token.NegationToken, "-"}, next())256 assert.Equal(token.Token{token.NumberToken, "5"}, next())257 assert.Equal(token.Token{token.SemicolonToken, ";"}, next())258 assert.Equal(token.Token{token.CloseBraceToken, "}"}, next())259 assert.Equal(token.EofToken, next().Type)260}261func TestLexNestedOps(t *testing.T) {262 assert := assert.New(t)263 input := `int main() {264 return !-3;265}`266 next := Lex(input).NextToken267 assert.Equal(token.Token{token.IntKeywordToken, "int"}, next())268 assert.Equal(token.Token{token.IdentifierToken, "main"}, next())269 assert.Equal(token.Token{token.OpenParenthesisToken, "("}, next())270 assert.Equal(token.Token{token.CloseParenthesisToken, ")"}, next())271 assert.Equal(token.Token{token.OpenBraceToken, "{"}, next())272 assert.Equal(token.Token{token.ReturnKeywordToken, "return"}, next())273 assert.Equal(token.Token{token.LogicalNegationToken, "!"}, next())274 assert.Equal(token.Token{token.NegationToken, "-"}, next())275 assert.Equal(token.Token{token.NumberToken, "3"}, next())276 assert.Equal(token.Token{token.SemicolonToken, ";"}, next())277 assert.Equal(token.Token{token.CloseBraceToken, "}"}, next())278 assert.Equal(token.EofToken, next().Type)279}280func TestLexNestedOps2(t *testing.T) {281 assert := assert.New(t)282 input := `int main() {283 return -~0;284}`285 next := Lex(input).NextToken286 assert.Equal(token.Token{token.IntKeywordToken, "int"}, next())287 assert.Equal(token.Token{token.IdentifierToken, "main"}, next())288 assert.Equal(token.Token{token.OpenParenthesisToken, "("}, next())289 assert.Equal(token.Token{token.CloseParenthesisToken, ")"}, next())290 assert.Equal(token.Token{token.OpenBraceToken, "{"}, next())291 assert.Equal(token.Token{token.ReturnKeywordToken, "return"}, next())292 assert.Equal(token.Token{token.NegationToken, "-"}, next())293 assert.Equal(token.Token{token.BitwiseComplementToken, "~"}, next())294 assert.Equal(token.Token{token.NumberToken, "0"}, next())295 assert.Equal(token.Token{token.SemicolonToken, ";"}, next())296 assert.Equal(token.Token{token.CloseBraceToken, "}"}, next())297 assert.Equal(token.EofToken, next().Type)298}299func TestLexNotFive(t *testing.T) {300 assert := assert.New(t)301 input := `int main() {302 return !5;303}`304 next := Lex(input).NextToken305 assert.Equal(token.Token{token.IntKeywordToken, "int"}, next())306 assert.Equal(token.Token{token.IdentifierToken, "main"}, next())307 assert.Equal(token.Token{token.OpenParenthesisToken, "("}, next())308 assert.Equal(token.Token{token.CloseParenthesisToken, ")"}, next())309 assert.Equal(token.Token{token.OpenBraceToken, "{"}, next())310 assert.Equal(token.Token{token.ReturnKeywordToken, "return"}, next())311 assert.Equal(token.Token{token.LogicalNegationToken, "!"}, next())312 assert.Equal(token.Token{token.NumberToken, "5"}, next())313 assert.Equal(token.Token{token.SemicolonToken, ";"}, next())314 assert.Equal(token.Token{token.CloseBraceToken, "}"}, next())315 assert.Equal(token.EofToken, next().Type)316}317func TestLexNotZero(t *testing.T) {318 assert := assert.New(t)319 input := `int main() {320 return !0;321}`322 next := Lex(input).NextToken323 assert.Equal(token.Token{token.IntKeywordToken, "int"}, next())324 assert.Equal(token.Token{token.IdentifierToken, "main"}, next())325 assert.Equal(token.Token{token.OpenParenthesisToken, "("}, next())326 assert.Equal(token.Token{token.CloseParenthesisToken, ")"}, next())327 assert.Equal(token.Token{token.OpenBraceToken, "{"}, next())328 assert.Equal(token.Token{token.ReturnKeywordToken, "return"}, next())329 assert.Equal(token.Token{token.LogicalNegationToken, "!"}, next())330 assert.Equal(token.Token{token.NumberToken, "0"}, next())331 assert.Equal(token.Token{token.SemicolonToken, ";"}, next())332 assert.Equal(token.Token{token.CloseBraceToken, "}"}, next())333 assert.Equal(token.EofToken, next().Type)334}335// Test inputs from github.com/nlsandler/write_a_c_compiler/stage_2/invalid336func TestLexMissingConst(t *testing.T) {337 assert := assert.New(t)338 input := `int main() {339 return !;340}`341 next := Lex(input).NextToken342 assert.Equal(token.Token{token.IntKeywordToken, "int"}, next())343 assert.Equal(token.Token{token.IdentifierToken, "main"}, next())344 assert.Equal(token.Token{token.OpenParenthesisToken, "("}, next())345 assert.Equal(token.Token{token.CloseParenthesisToken, ")"}, next())346 assert.Equal(token.Token{token.OpenBraceToken, "{"}, next())347 assert.Equal(token.Token{token.ReturnKeywordToken, "return"}, next())348 assert.Equal(token.Token{token.LogicalNegationToken, "!"}, next())349 assert.Equal(token.Token{token.SemicolonToken, ";"}, next())350 assert.Equal(token.Token{token.CloseBraceToken, "}"}, next())351 assert.Equal(token.EofToken, next().Type)352}353func TestLexMissingSemicolon(t *testing.T) {354 assert := assert.New(t)355 input := `int main() {356 return !5357}`358 next := Lex(input).NextToken359 assert.Equal(token.Token{token.IntKeywordToken, "int"}, next())360 assert.Equal(token.Token{token.IdentifierToken, "main"}, next())361 assert.Equal(token.Token{token.OpenParenthesisToken, "("}, next())362 assert.Equal(token.Token{token.CloseParenthesisToken, ")"}, next())363 assert.Equal(token.Token{token.OpenBraceToken, "{"}, next())364 assert.Equal(token.Token{token.ReturnKeywordToken, "return"}, next())365 assert.Equal(token.Token{token.LogicalNegationToken, "!"}, next())366 assert.Equal(token.Token{token.NumberToken, "5"}, next())367 assert.Equal(token.Token{token.CloseBraceToken, "}"}, next())368 assert.Equal(token.EofToken, next().Type)369}370func TestLexNestedMissingConst(t *testing.T) {371 assert := assert.New(t)372 input := `int main() {373 return !~;374}`375 next := Lex(input).NextToken376 assert.Equal(token.Token{token.IntKeywordToken, "int"}, next())377 assert.Equal(token.Token{token.IdentifierToken, "main"}, next())378 assert.Equal(token.Token{token.OpenParenthesisToken, "("}, next())379 assert.Equal(token.Token{token.CloseParenthesisToken, ")"}, next())380 assert.Equal(token.Token{token.OpenBraceToken, "{"}, next())381 assert.Equal(token.Token{token.ReturnKeywordToken, "return"}, next())382 assert.Equal(token.Token{token.LogicalNegationToken, "!"}, next())383 assert.Equal(token.Token{token.BitwiseComplementToken, "~"}, next())384 assert.Equal(token.Token{token.SemicolonToken, ";"}, next())385 assert.Equal(token.Token{token.CloseBraceToken, "}"}, next())386 assert.Equal(token.EofToken, next().Type)387}388func TestLexWrongOrder(t *testing.T) {389 assert := assert.New(t)390 input := `int main() {391 return 4-;392}`393 next := Lex(input).NextToken394 assert.Equal(token.Token{token.IntKeywordToken, "int"}, next())395 assert.Equal(token.Token{token.IdentifierToken, "main"}, next())396 assert.Equal(token.Token{token.OpenParenthesisToken, "("}, next())397 assert.Equal(token.Token{token.CloseParenthesisToken, ")"}, next())398 assert.Equal(token.Token{token.OpenBraceToken, "{"}, next())399 assert.Equal(token.Token{token.ReturnKeywordToken, "return"}, next())400 assert.Equal(token.Token{token.NumberToken, "4"}, next())401 assert.Equal(token.Token{token.NegationToken, "-"}, next())402 assert.Equal(token.Token{token.SemicolonToken, ";"}, next())403 assert.Equal(token.Token{token.CloseBraceToken, "}"}, next())404 assert.Equal(token.EofToken, next().Type)405}406// Test inputs from github.com/nlsandler/write_a_c_compiler/stage_3/valid407func TestLexAssociativity(t *testing.T) {408 assert := assert.New(t)409 input := `int main() { return 1 - 2 - 3; }`410 next := Lex(input).NextToken411 assert.Equal(token.Token{token.IntKeywordToken, "int"}, next())412 assert.Equal(token.Token{token.IdentifierToken, "main"}, next())413 assert.Equal(token.Token{token.OpenParenthesisToken, "("}, next())414 assert.Equal(token.Token{token.CloseParenthesisToken, ")"}, next())415 assert.Equal(token.Token{token.OpenBraceToken, "{"}, next())416 assert.Equal(token.Token{token.ReturnKeywordToken, "return"}, next())417 assert.Equal(token.Token{token.NumberToken, "1"}, next())418 assert.Equal(token.Token{token.NegationToken, "-"}, next())419 assert.Equal(token.Token{token.NumberToken, "2"}, next())420 assert.Equal(token.Token{token.NegationToken, "-"}, next())421 assert.Equal(token.Token{token.NumberToken, "3"}, next())422 assert.Equal(token.Token{token.SemicolonToken, ";"}, next())423 assert.Equal(token.Token{token.CloseBraceToken, "}"}, next())424 assert.Equal(token.EofToken, next().Type)425}426// Test inputs from github.com/nlsandler/write_a_c_compiler/stage_4/valid427func TestLexAndFalse(t *testing.T) {428 assert := assert.New(t)429 input := `int main() { return 1 && 0; }`430 next := Lex(input).NextToken431 assert.Equal(token.Token{token.IntKeywordToken, "int"}, next())432 assert.Equal(token.Token{token.IdentifierToken, "main"}, next())433 assert.Equal(token.Token{token.OpenParenthesisToken, "("}, next())434 assert.Equal(token.Token{token.CloseParenthesisToken, ")"}, next())435 assert.Equal(token.Token{token.OpenBraceToken, "{"}, next())436 assert.Equal(token.Token{token.ReturnKeywordToken, "return"}, next())437 assert.Equal(token.Token{token.NumberToken, "1"}, next())438 assert.Equal(token.Token{token.AndToken, "&&"}, next())439 assert.Equal(token.Token{token.NumberToken, "0"}, next())440 assert.Equal(token.Token{token.SemicolonToken, ";"}, next())441 assert.Equal(token.Token{token.CloseBraceToken, "}"}, next())442 assert.Equal(token.EofToken, next().Type)443}444func TestLexAndTrue(t *testing.T) {445 assert := assert.New(t)446 input := `int main() { return 1 && -1; }`447 next := Lex(input).NextToken448 assert.Equal(token.Token{token.IntKeywordToken, "int"}, next())449 assert.Equal(token.Token{token.IdentifierToken, "main"}, next())450 assert.Equal(token.Token{token.OpenParenthesisToken, "("}, next())451 assert.Equal(token.Token{token.CloseParenthesisToken, ")"}, next())452 assert.Equal(token.Token{token.OpenBraceToken, "{"}, next())453 assert.Equal(token.Token{token.ReturnKeywordToken, "return"}, next())454 assert.Equal(token.Token{token.NumberToken, "1"}, next())455 assert.Equal(token.Token{token.AndToken, "&&"}, next())456 assert.Equal(token.Token{token.NegationToken, "-"}, next())457 assert.Equal(token.Token{token.NumberToken, "1"}, next())458 assert.Equal(token.Token{token.SemicolonToken, ";"}, next())459 assert.Equal(token.Token{token.CloseBraceToken, "}"}, next())460 assert.Equal(token.EofToken, next().Type)461}462func TestLexPrecedence(t *testing.T) {463 assert := assert.New(t)464 input := `int main() { return 1 || 0 && 2; }`465 next := Lex(input).NextToken466 assert.Equal(token.Token{token.IntKeywordToken, "int"}, next())467 assert.Equal(token.Token{token.IdentifierToken, "main"}, next())468 assert.Equal(token.Token{token.OpenParenthesisToken, "("}, next())469 assert.Equal(token.Token{token.CloseParenthesisToken, ")"}, next())470 assert.Equal(token.Token{token.OpenBraceToken, "{"}, next())471 assert.Equal(token.Token{token.ReturnKeywordToken, "return"}, next())472 assert.Equal(token.Token{token.NumberToken, "1"}, next())473 assert.Equal(token.Token{token.OrToken, "||"}, next())474 assert.Equal(token.Token{token.NumberToken, "0"}, next())475 assert.Equal(token.Token{token.AndToken, "&&"}, next())476 assert.Equal(token.Token{token.NumberToken, "2"}, next())477 assert.Equal(token.Token{token.SemicolonToken, ";"}, next())478 assert.Equal(token.Token{token.CloseBraceToken, "}"}, next())479 assert.Equal(token.EofToken, next().Type)480}...

Full Screen

Full Screen

parser_test.go

Source:parser_test.go Github

copy

Full Screen

...59 token.Token{token.OpenParenthesisToken, "("},60 token.Token{token.NumberToken, "2"},61 token.Token{token.MultiplicationToken, "*"},62 token.Token{token.NumberToken, "3"},63 token.Token{token.CloseParenthesisToken, ")"},64 token.Token{token.CloseParenthesisToken, ")"},65 token.Token{token.SemicolonToken, ";"},66 })67 p, err := ParseStatement(ts)68 assert.Nil(err)69 assert.NotNil(p)70 assert.Equal("RETURN (Int<1> + (Int<2> * Int<3>))", p.String())71}72// Test inputs from github.com/nlsandler/write_a_c_compiler/stage_1/valid73func TestParseMultiDigit(t *testing.T) {74 assert := assert.New(t)75 ts := token.NewSliceTokenStream([]token.Token{76 token.Token{token.IntKeywordToken, "int"},77 token.Token{token.IdentifierToken, "main"},78 token.Token{token.OpenParenthesisToken, "("},79 token.Token{token.CloseParenthesisToken, ")"},80 token.Token{token.OpenBraceToken, "{"},81 token.Token{token.ReturnKeywordToken, "return"},82 token.Token{token.NumberToken, "100"},83 token.Token{token.SemicolonToken, ";"},84 token.Token{token.CloseBraceToken, "}"},85 })86 p, err := Parse(ts)87 assert.Equal(nil, err)88 assert.NotEqual(nil, p.Function)89 assert.Equal("main", p.Function.Identifier)90 assert.NotEqual(nil, p.Function.Statement)91 assert.NotEqual(nil, p.Function.Statement.Expression)92 assert.Equal("Int<100>", p.Function.Statement.Expression.String())93}94func TestParseNewlines(t *testing.T) {95 assert := assert.New(t)96 ts := token.NewSliceTokenStream([]token.Token{97 token.Token{token.IntKeywordToken, "int"},98 token.Token{token.IdentifierToken, "main"},99 token.Token{token.OpenParenthesisToken, "("},100 token.Token{token.CloseParenthesisToken, ")"},101 token.Token{token.OpenBraceToken, "{"},102 token.Token{token.ReturnKeywordToken, "return"},103 token.Token{token.NumberToken, "0"},104 token.Token{token.SemicolonToken, ";"},105 token.Token{token.CloseBraceToken, "}"},106 })107 p, err := Parse(ts)108 assert.Equal(nil, err)109 assert.NotEqual(nil, p.Function)110 assert.Equal("main", p.Function.Identifier)111 assert.NotEqual(nil, p.Function.Statement)112 assert.NotEqual(nil, p.Function.Statement.Expression)113 assert.Equal("Int<0>", p.Function.Statement.Expression.String())114}115func TestParseNoNewlines(t *testing.T) {116 assert := assert.New(t)117 ts := token.NewSliceTokenStream([]token.Token{118 token.Token{token.IntKeywordToken, "int"},119 token.Token{token.IdentifierToken, "main"},120 token.Token{token.OpenParenthesisToken, "("},121 token.Token{token.CloseParenthesisToken, ")"},122 token.Token{token.OpenBraceToken, "{"},123 token.Token{token.ReturnKeywordToken, "return"},124 token.Token{token.NumberToken, "0"},125 token.Token{token.SemicolonToken, ";"},126 token.Token{token.CloseBraceToken, "}"},127 })128 p, err := Parse(ts)129 assert.Equal(nil, err)130 assert.NotEqual(nil, p.Function)131 assert.Equal("main", p.Function.Identifier)132 assert.NotEqual(nil, p.Function.Statement)133 assert.NotEqual(nil, p.Function.Statement.Expression)134 assert.Equal("Int<0>", p.Function.Statement.Expression.String())135}136func TestParseReturn0(t *testing.T) {137 assert := assert.New(t)138 ts := token.NewSliceTokenStream([]token.Token{139 token.Token{token.IntKeywordToken, "int"},140 token.Token{token.IdentifierToken, "main"},141 token.Token{token.OpenParenthesisToken, "("},142 token.Token{token.CloseParenthesisToken, ")"},143 token.Token{token.OpenBraceToken, "{"},144 token.Token{token.ReturnKeywordToken, "return"},145 token.Token{token.NumberToken, "0"},146 token.Token{token.SemicolonToken, ";"},147 token.Token{token.CloseBraceToken, "}"},148 })149 p, err := Parse(ts)150 assert.Equal(nil, err)151 assert.NotEqual(nil, p.Function)152 assert.Equal("main", p.Function.Identifier)153 assert.NotEqual(nil, p.Function.Statement)154 assert.NotEqual(nil, p.Function.Statement.Expression)155 assert.Equal("Int<0>", p.Function.Statement.Expression.String())156}157func TestParseReturn2(t *testing.T) {158 assert := assert.New(t)159 ts := token.NewSliceTokenStream([]token.Token{160 token.Token{token.IntKeywordToken, "int"},161 token.Token{token.IdentifierToken, "main"},162 token.Token{token.OpenParenthesisToken, "("},163 token.Token{token.CloseParenthesisToken, ")"},164 token.Token{token.OpenBraceToken, "{"},165 token.Token{token.ReturnKeywordToken, "return"},166 token.Token{token.NumberToken, "2"},167 token.Token{token.SemicolonToken, ";"},168 token.Token{token.CloseBraceToken, "}"},169 })170 p, err := Parse(ts)171 assert.Equal(nil, err)172 assert.NotEqual(nil, p.Function)173 assert.Equal("main", p.Function.Identifier)174 assert.NotEqual(nil, p.Function.Statement)175 assert.NotEqual(nil, p.Function.Statement.Expression)176 assert.Equal("Int<2>", p.Function.Statement.Expression.String())177}178func TestParseSpaces(t *testing.T) {179 assert := assert.New(t)180 ts := token.NewSliceTokenStream([]token.Token{181 token.Token{token.IntKeywordToken, "int"},182 token.Token{token.IdentifierToken, "main"},183 token.Token{token.OpenParenthesisToken, "("},184 token.Token{token.CloseParenthesisToken, ")"},185 token.Token{token.OpenBraceToken, "{"},186 token.Token{token.ReturnKeywordToken, "return"},187 token.Token{token.NumberToken, "0"},188 token.Token{token.SemicolonToken, ";"},189 token.Token{token.CloseBraceToken, "}"},190 })191 p, err := Parse(ts)192 assert.Equal(nil, err)193 assert.NotEqual(nil, p.Function)194 assert.Equal("main", p.Function.Identifier)195 assert.NotEqual(nil, p.Function.Statement)196 assert.NotEqual(nil, p.Function.Statement.Expression)197 assert.Equal("Int<0>", p.Function.Statement.Expression.String())198}199// Test inputs from github.com/nlsandler/write_a_c_compiler/stage_1/invalid200func TestParseMissingParen(t *testing.T) {201 assert := assert.New(t)202 ts := token.NewSliceTokenStream([]token.Token{203 token.Token{token.IntKeywordToken, "int"},204 token.Token{token.IdentifierToken, "main"},205 token.Token{token.OpenParenthesisToken, "("},206 token.Token{token.OpenBraceToken, "{"},207 token.Token{token.ReturnKeywordToken, "return"},208 token.Token{token.NumberToken, "0"},209 token.Token{token.SemicolonToken, ";"},210 token.Token{token.CloseBraceToken, "}"},211 })212 p, err := Parse(ts)213 assert.NotNil(err)214 assert.Nil(p)215}216func TestParseMissingRetval(t *testing.T) {217 assert := assert.New(t)218 ts := token.NewSliceTokenStream([]token.Token{219 token.Token{token.IntKeywordToken, "int"},220 token.Token{token.IdentifierToken, "main"},221 token.Token{token.OpenParenthesisToken, "("},222 token.Token{token.CloseParenthesisToken, ")"},223 token.Token{token.OpenBraceToken, "{"},224 token.Token{token.ReturnKeywordToken, "return"},225 token.Token{token.SemicolonToken, ";"},226 token.Token{token.CloseBraceToken, "}"},227 })228 p, err := Parse(ts)229 assert.NotNil(err)230 assert.Nil(p)231}232func TestParseNoBrace(t *testing.T) {233 assert := assert.New(t)234 ts := token.NewSliceTokenStream([]token.Token{235 token.Token{token.IntKeywordToken, "int"},236 token.Token{token.IdentifierToken, "main"},237 token.Token{token.OpenBraceToken, "{"},238 token.Token{token.ReturnKeywordToken, "return"},239 token.Token{token.NumberToken, "0"},240 token.Token{token.SemicolonToken, ";"},241 })242 p, err := Parse(ts)243 assert.NotNil(err)244 assert.Nil(p)245}246func TestParseNoSemicolon(t *testing.T) {247 assert := assert.New(t)248 ts := token.NewSliceTokenStream([]token.Token{249 token.Token{token.IntKeywordToken, "int"},250 token.Token{token.IdentifierToken, "main"},251 token.Token{token.OpenBraceToken, "{"},252 token.Token{token.ReturnKeywordToken, "return"},253 token.Token{token.NumberToken, "0"},254 token.Token{token.CloseBraceToken, "}"},255 })256 p, err := Parse(ts)257 assert.NotNil(err)258 assert.Nil(p)259}260func TestParseNoSpace(t *testing.T) {261 assert := assert.New(t)262 ts := token.NewSliceTokenStream([]token.Token{263 token.Token{token.IntKeywordToken, "int"},264 token.Token{token.IdentifierToken, "main"},265 token.Token{token.OpenParenthesisToken, "("},266 token.Token{token.CloseParenthesisToken, ")"},267 token.Token{token.OpenBraceToken, "{"},268 token.Token{token.IdentifierToken, "return0"},269 token.Token{token.SemicolonToken, ";"},270 token.Token{token.CloseBraceToken, "}"},271 })272 p, err := Parse(ts)273 assert.NotNil(err)274 assert.Nil(p)275}276func TestParseWrongCase(t *testing.T) {277 assert := assert.New(t)278 ts := token.NewSliceTokenStream([]token.Token{279 token.Token{token.IntKeywordToken, "int"},280 token.Token{token.IdentifierToken, "main"},281 token.Token{token.OpenParenthesisToken, "("},282 token.Token{token.CloseParenthesisToken, ")"},283 token.Token{token.OpenBraceToken, "{"},284 token.Token{token.IdentifierToken, "RETURN"},285 token.Token{token.NumberToken, "0"},286 token.Token{token.SemicolonToken, ";"},287 token.Token{token.CloseBraceToken, "}"},288 })289 p, err := Parse(ts)290 assert.NotNil(err)291 assert.Nil(p)292}293// Test inputs from github.com/nlsandler/write_a_c_compiler/stage_2/valid294func TestParseBitwise(t *testing.T) {295 assert := assert.New(t)296 ts := token.NewSliceTokenStream([]token.Token{297 token.Token{token.IntKeywordToken, "int"},298 token.Token{token.IdentifierToken, "main"},299 token.Token{token.OpenParenthesisToken, "("},300 token.Token{token.CloseParenthesisToken, ")"},301 token.Token{token.OpenBraceToken, "{"},302 token.Token{token.ReturnKeywordToken, "return"},303 token.Token{token.LogicalNegationToken, "!"},304 token.Token{token.NumberToken, "12"},305 token.Token{token.SemicolonToken, ";"},306 token.Token{token.CloseBraceToken, "}"},307 })308 p, err := Parse(ts)309 assert.Equal(nil, err)310 assert.NotEqual(nil, p.Function)311 assert.Equal("main", p.Function.Identifier)312 assert.NotEqual(nil, p.Function.Statement)313 assert.NotEqual(nil, p.Function.Statement.Expression)314 assert.Equal("! Int<12>", p.Function.Statement.Expression.String())315}316func TestParseBitwiseZero(t *testing.T) {317 assert := assert.New(t)318 ts := token.NewSliceTokenStream([]token.Token{319 token.Token{token.IntKeywordToken, "int"},320 token.Token{token.IdentifierToken, "main"},321 token.Token{token.OpenParenthesisToken, "("},322 token.Token{token.CloseParenthesisToken, ")"},323 token.Token{token.OpenBraceToken, "{"},324 token.Token{token.ReturnKeywordToken, "return"},325 token.Token{token.BitwiseComplementToken, "~"},326 token.Token{token.NumberToken, "0"},327 token.Token{token.SemicolonToken, ";"},328 token.Token{token.CloseBraceToken, "}"},329 })330 p, err := Parse(ts)331 assert.Equal(nil, err)332 assert.NotEqual(nil, p.Function)333 assert.Equal("main", p.Function.Identifier)334 assert.NotEqual(nil, p.Function.Statement)335 assert.NotEqual(nil, p.Function.Statement.Expression)336 assert.Equal("~ Int<0>", p.Function.Statement.Expression.String())337}338func TestParseNeg(t *testing.T) {339 assert := assert.New(t)340 ts := token.NewSliceTokenStream([]token.Token{341 token.Token{token.IntKeywordToken, "int"},342 token.Token{token.IdentifierToken, "main"},343 token.Token{token.OpenParenthesisToken, "("},344 token.Token{token.CloseParenthesisToken, ")"},345 token.Token{token.OpenBraceToken, "{"},346 token.Token{token.ReturnKeywordToken, "return"},347 token.Token{token.NegationToken, "-"},348 token.Token{token.NumberToken, "5"},349 token.Token{token.SemicolonToken, ";"},350 token.Token{token.CloseBraceToken, "}"},351 })352 p, err := Parse(ts)353 assert.Equal(nil, err)354 assert.NotEqual(nil, p.Function)355 assert.Equal("main", p.Function.Identifier)356 assert.NotEqual(nil, p.Function.Statement)357 assert.NotEqual(nil, p.Function.Statement.Expression)358 assert.Equal("- Int<5>", p.Function.Statement.Expression.String())359}360func TestParseNestedOps(t *testing.T) {361 assert := assert.New(t)362 ts := token.NewSliceTokenStream([]token.Token{363 token.Token{token.IntKeywordToken, "int"},364 token.Token{token.IdentifierToken, "main"},365 token.Token{token.OpenParenthesisToken, "("},366 token.Token{token.CloseParenthesisToken, ")"},367 token.Token{token.OpenBraceToken, "{"},368 token.Token{token.ReturnKeywordToken, "return"},369 token.Token{token.LogicalNegationToken, "!"},370 token.Token{token.NegationToken, "-"},371 token.Token{token.NumberToken, "3"},372 token.Token{token.SemicolonToken, ";"},373 token.Token{token.CloseBraceToken, "}"},374 })375 p, err := Parse(ts)376 assert.Equal(nil, err)377 assert.NotEqual(nil, p.Function)378 assert.Equal("main", p.Function.Identifier)379 assert.NotEqual(nil, p.Function.Statement)380 assert.NotEqual(nil, p.Function.Statement.Expression)381 assert.Equal("! - Int<3>", p.Function.Statement.Expression.String())382}383func TestParseNestedOps2(t *testing.T) {384 assert := assert.New(t)385 ts := token.NewSliceTokenStream([]token.Token{386 token.Token{token.IntKeywordToken, "int"},387 token.Token{token.IdentifierToken, "main"},388 token.Token{token.OpenParenthesisToken, "("},389 token.Token{token.CloseParenthesisToken, ")"},390 token.Token{token.OpenBraceToken, "{"},391 token.Token{token.ReturnKeywordToken, "return"},392 token.Token{token.NegationToken, "-"},393 token.Token{token.BitwiseComplementToken, "~"},394 token.Token{token.NumberToken, "0"},395 token.Token{token.SemicolonToken, ";"},396 token.Token{token.CloseBraceToken, "}"},397 })398 p, err := Parse(ts)399 assert.Equal(nil, err)400 assert.NotEqual(nil, p.Function)401 assert.Equal("main", p.Function.Identifier)402 assert.NotEqual(nil, p.Function.Statement)403 assert.NotEqual(nil, p.Function.Statement.Expression)404 assert.Equal("- ~ Int<0>", p.Function.Statement.Expression.String())405}406func TestParseNotFive(t *testing.T) {407 assert := assert.New(t)408 ts := token.NewSliceTokenStream([]token.Token{409 token.Token{token.IntKeywordToken, "int"},410 token.Token{token.IdentifierToken, "main"},411 token.Token{token.OpenParenthesisToken, "("},412 token.Token{token.CloseParenthesisToken, ")"},413 token.Token{token.OpenBraceToken, "{"},414 token.Token{token.ReturnKeywordToken, "return"},415 token.Token{token.LogicalNegationToken, "!"},416 token.Token{token.NumberToken, "5"},417 token.Token{token.SemicolonToken, ";"},418 token.Token{token.CloseBraceToken, "}"},419 })420 p, err := Parse(ts)421 assert.Equal(nil, err)422 assert.NotEqual(nil, p.Function)423 assert.Equal("main", p.Function.Identifier)424 assert.NotEqual(nil, p.Function.Statement)425 assert.NotEqual(nil, p.Function.Statement.Expression)426 assert.Equal("! Int<5>", p.Function.Statement.Expression.String())427}428func TestParseNotZero(t *testing.T) {429 assert := assert.New(t)430 ts := token.NewSliceTokenStream([]token.Token{431 token.Token{token.IntKeywordToken, "int"},432 token.Token{token.IdentifierToken, "main"},433 token.Token{token.OpenParenthesisToken, "("},434 token.Token{token.CloseParenthesisToken, ")"},435 token.Token{token.OpenBraceToken, "{"},436 token.Token{token.ReturnKeywordToken, "return"},437 token.Token{token.LogicalNegationToken, "!"},438 token.Token{token.NumberToken, "0"},439 token.Token{token.SemicolonToken, ";"},440 token.Token{token.CloseBraceToken, "}"},441 })442 p, err := Parse(ts)443 assert.Equal(nil, err)444 assert.NotEqual(nil, p.Function)445 assert.Equal("main", p.Function.Identifier)446 assert.NotEqual(nil, p.Function.Statement)447 assert.NotEqual(nil, p.Function.Statement.Expression)448 assert.Equal("! Int<0>", p.Function.Statement.Expression.String())449}450// Test inputs from github.com/nlsandler/write_a_c_compiler/stage_2/invalid451func TestParseMissingConst(t *testing.T) {452 assert := assert.New(t)453 ts := token.NewSliceTokenStream([]token.Token{454 token.Token{token.IntKeywordToken, "int"},455 token.Token{token.IdentifierToken, "main"},456 token.Token{token.OpenParenthesisToken, "("},457 token.Token{token.CloseParenthesisToken, ")"},458 token.Token{token.OpenBraceToken, "{"},459 token.Token{token.ReturnKeywordToken, "return"},460 token.Token{token.LogicalNegationToken, "!"},461 token.Token{token.SemicolonToken, ";"},462 token.Token{token.CloseBraceToken, "}"},463 })464 p, err := Parse(ts)465 assert.NotNil(err)466 assert.Nil(p)467}468func TestParseMissingSemicolon(t *testing.T) {469 assert := assert.New(t)470 ts := token.NewSliceTokenStream([]token.Token{471 token.Token{token.IntKeywordToken, "int"},472 token.Token{token.IdentifierToken, "main"},473 token.Token{token.OpenParenthesisToken, "("},474 token.Token{token.CloseParenthesisToken, ")"},475 token.Token{token.OpenBraceToken, "{"},476 token.Token{token.ReturnKeywordToken, "return"},477 token.Token{token.LogicalNegationToken, "!"},478 token.Token{token.NumberToken, "5"},479 token.Token{token.CloseBraceToken, "}"},480 })481 p, err := Parse(ts)482 assert.NotNil(err)483 assert.Nil(p)484}485func TestParseNestedMissingConst(t *testing.T) {486 assert := assert.New(t)487 ts := token.NewSliceTokenStream([]token.Token{488 token.Token{token.IntKeywordToken, "int"},489 token.Token{token.IdentifierToken, "main"},490 token.Token{token.OpenParenthesisToken, "("},491 token.Token{token.CloseParenthesisToken, ")"},492 token.Token{token.OpenBraceToken, "{"},493 token.Token{token.ReturnKeywordToken, "return"},494 token.Token{token.LogicalNegationToken, "!"},495 token.Token{token.BitwiseComplementToken, "~"},496 token.Token{token.SemicolonToken, ";"},497 token.Token{token.CloseBraceToken, "}"},498 })499 p, err := Parse(ts)500 assert.NotNil(err)501 assert.Nil(p)502}503func TestParseWrongOrder(t *testing.T) {504 assert := assert.New(t)505 ts := token.NewSliceTokenStream([]token.Token{506 token.Token{token.IntKeywordToken, "int"},507 token.Token{token.IdentifierToken, "main"},508 token.Token{token.OpenParenthesisToken, "("},509 token.Token{token.CloseParenthesisToken, ")"},510 token.Token{token.OpenBraceToken, "{"},511 token.Token{token.ReturnKeywordToken, "return"},512 token.Token{token.NumberToken, "4"},513 token.Token{token.NegationToken, "-"},514 token.Token{token.SemicolonToken, ";"},515 token.Token{token.CloseBraceToken, "}"},516 })517 p, err := Parse(ts)518 assert.NotNil(err)519 assert.Nil(p)520}521// Test inputs from github.com/nlsandler/write_a_c_compiler/stage_3/valid522func TestParseAssociativity(t *testing.T) {523 assert := assert.New(t)524 // int main() { return 1 - 2 - 3; }525 ts := token.NewSliceTokenStream([]token.Token{526 token.Token{token.IntKeywordToken, "int"},527 token.Token{token.IdentifierToken, "main"},528 token.Token{token.OpenParenthesisToken, "("},529 token.Token{token.CloseParenthesisToken, ")"},530 token.Token{token.OpenBraceToken, "{"},531 token.Token{token.ReturnKeywordToken, "return"},532 token.Token{token.NumberToken, "1"},533 token.Token{token.NegationToken, "-"},534 token.Token{token.NumberToken, "2"},535 token.Token{token.NegationToken, "-"},536 token.Token{token.NumberToken, "3"},537 token.Token{token.SemicolonToken, ";"},538 token.Token{token.CloseBraceToken, "}"},539 })540 p, err := Parse(ts)541 assert.Equal(nil, err)542 assert.NotEqual(nil, p.Function)543 assert.Equal("main", p.Function.Identifier)544 assert.NotEqual(nil, p.Function.Statement)545 assert.NotEqual(nil, p.Function.Statement.Expression)546 assert.Equal("((Int<1> - Int<2>) - Int<3>)",547 p.Function.Statement.Expression.String())548}...

Full Screen

Full Screen

cachedstore_test.go

Source:cachedstore_test.go Github

copy

Full Screen

...49 err = cachedProvider.SetStoreConfig("StoreName", spi.StoreConfiguration{})50 require.EqualError(t, err, "failed to set store configuration in cache provider: set config failure")51 })52}53func TestCachedProvider_Close(t *testing.T) {54 t.Run("Fail to close the main provider", func(t *testing.T) {55 provider := cachedstore.NewProvider(&mock.Provider{ErrClose: errors.New("close failure")}, mem.NewProvider())56 err := provider.Close()57 require.EqualError(t, err, "failed to close main provider: close failure")58 })59 t.Run("Fail to close the cache provider", func(t *testing.T) {60 provider := cachedstore.NewProvider(mem.NewProvider(),61 &mock.Provider{ErrClose: errors.New("close failure")})62 err := provider.Close()63 require.EqualError(t, err, "failed to close cache provider: close failure")64 })65}66func TestStore_Put(t *testing.T) {67 t.Run("Fail to put data in the cache store", func(t *testing.T) {68 provider := cachedstore.NewProvider(mem.NewProvider(),69 &mock.Provider{OpenStoreReturn: &mock.Store{ErrPut: errors.New("put failure")}})70 store, err := provider.OpenStore("TestStore")71 require.NoError(t, err)72 err = store.Put("key", []byte("value"))73 require.EqualError(t, err, "failed to put key, values and tags in the cache store: put failure")74 })75}76func TestStore_Get(t *testing.T) {77 t.Run("Fail to put newly retrieved data into the cache store", func(t *testing.T) {78 mainProvider := mem.NewProvider()79 mainStore, err := mainProvider.OpenStore("TestStore")80 require.NoError(t, err)81 err = mainStore.Put("key", []byte("value"))82 require.NoError(t, err)83 provider := cachedstore.NewProvider(mainProvider,84 &mock.Provider{OpenStoreReturn: &mock.Store{85 ErrGet: spi.ErrDataNotFound, ErrPut: errors.New("put failure"),86 }})87 store, err := provider.OpenStore("TestStore")88 require.NoError(t, err)89 _, err = store.Get("key")90 require.EqualError(t, err,91 "failed to put the newly retrieved data into the cache store for future use: put failure")92 })93}94func TestStore_Close(t *testing.T) {95 t.Run("Fail to close the main store", func(t *testing.T) {96 provider := cachedstore.NewProvider(97 &mock.Provider{OpenStoreReturn: &mock.Store{ErrClose: errors.New("close failure")}}, mem.NewProvider())98 store, err := provider.OpenStore("TestStore")99 require.NoError(t, err)100 err = store.Close()101 require.EqualError(t, err, "failed to close the main store: close failure")102 })103 t.Run("Fail to close the cache store", func(t *testing.T) {104 provider := cachedstore.NewProvider(105 mem.NewProvider(), &mock.Provider{OpenStoreReturn: &mock.Store{ErrClose: errors.New("close failure")}})106 store, err := provider.OpenStore("TestStore")107 require.NoError(t, err)108 err = store.Close()109 require.EqualError(t, err, "failed to close the cache store: close failure")110 })111}...

Full Screen

Full Screen

Close

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Scanln(&input)4 fmt.Println("Done")5}6import "fmt"7func main() {8 fmt.Scanln(&input)9 fmt.Println("Done")10 Close()11}

Full Screen

Full Screen

Close

Using AI Code Generation

copy

Full Screen

1import "fmt"2func (i MyInt) Close() error {3 fmt.Println("Close called")4}5func main() {6 i.Close()7}

Full Screen

Full Screen

Close

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "os"3func main() {4 f, err := os.Open("2.go")5 if err != nil {6 fmt.Printf("error opening file: %v7 os.Exit(1)8 }9 defer f.Close()10 fmt.Printf("file opened successfully: %v11", f.Name())12}

Full Screen

Full Screen

Close

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 f := NewFile("file.txt")4 f.Close()5}6import "fmt"7func main() {8 f := NewFile("file.txt")9 defer f.Close()10}11import "fmt"12func main() {13 f := NewFile("file.txt")14 defer f.Close()15 f.Write([]byte("data"))16}17import "fmt"18func main() {19 f := NewFile("file.txt")20 f.Write([]byte("data"))21 f.Close()22}23import "fmt"24func main() {25 f := NewFile("file.txt")26 f.Write([]byte("data"))27 f.Close()28 f.Write([]byte("data"))29}30import "fmt"31func main() {32 f := NewFile("file.txt")33 defer f.Close()34 f.Write([]byte("data"))35 f.Write([]byte("data"))36}37import "fmt"38func main() {39 f := NewFile("file.txt")40 defer f.Close()41 f.Write([]byte("data"))42}43import "fmt"44func main() {45 f := NewFile("file.txt")46 defer f.Close()47 f.Write([]byte("data"))48 f.Close()49}50import "fmt"51func main() {52 f := NewFile("file.txt")53 defer f.Close()54 f.Write([]byte("data"))55 f.Write([]byte("data"))56 f.Close()57}58import "fmt"59func main() {60 f := NewFile("file.txt")61 defer f.Close()

Full Screen

Full Screen

Close

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 f, err := os.Open("test.txt")4 if err != nil {5 panic(err)6 }7 defer f.Close()8 b := make([]byte, 5)9 for {10 n, err := f.Read(b)11 if err != nil {12 if err == io.EOF {13 }14 panic(err)15 }16 fmt.Println(string(b[:n]))17 }18}19import (20func main() {21 f, err := os.Open("test.txt")22 if err != nil {23 panic(err)24 }25 defer f.Close()26 b := make([]byte, 5)27 for {28 n, err := f.Read(b)29 if err != nil {30 if err == io.EOF {31 }32 panic(err)33 }34 fmt.Println(string(b[:n]))35 }36}37import (38func main() {39 f, err := os.Open("test.txt")40 if err != nil {41 panic(err)42 }43 defer f.Close()44 b := make([]byte, 5)45 for {46 n, err := f.Read(b)47 if err != nil {48 if err == io.EOF {49 }50 panic(err)51 }52 fmt.Println(string(b[:n]))53 }54}55import (56func main() {57 f, err := os.Open("test.txt")58 if err != nil {59 panic(err)60 }61 defer f.Close()62 b := make([]byte, 5)63 for {64 n, err := f.Read(b)65 if err != nil {66 if err == io.EOF {67 }68 panic(err)69 }70 fmt.Println(string(b[:n]))

Full Screen

Full Screen

Close

Using AI Code Generation

copy

Full Screen

1import (2type main struct {3}4func (m *main) Close() {5 fmt.Println("Close method of main class")6}7func main() {8 m.Close()9}10import (11type main struct {12}13func (m *main) Close() {14 fmt.Println("Close method of main class")15}16func main() {17 m.Close()18}19import (20type main struct {21}22func (m *main) Close() {23 fmt.Println("Close method of main class")24}25func main() {26 m.Close()27}28import (29type main struct {30}31func (m *main) Close() {32 fmt.Println("Close method of main class")33}34func main() {35 m.Close()36}37import (38type main struct {39}40func (m *main) Close() {41 fmt.Println("Close method of main class")42}43func main() {44 m.Close()45}46import (47type main struct {48}49func (m *main) Close() {50 fmt.Println("Close method of main class")51}52func main() {53 m.Close()54}55import (56type main struct {57}58func (m *main) Close() {59 fmt.Println("Close method of main class")60}61func main() {62 m.Close()63}64import (65type main struct {66}67func (

Full Screen

Full Screen

Close

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("hello world")4 var c1 = new(Close)5 c1.Close()6}7func (c *Close) Close() {8 fmt.Println("Close method called")9}

Full Screen

Full Screen

Close

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello, World!")4 obj1.Close()5}6import "fmt"7func main() {8 fmt.Println("Hello, World!")9 obj1.Close()10}11import "fmt"12func main() {13 fmt.Println("Hello, World!")14 obj1.Close()15}16import "fmt"17func main() {18 fmt.Println("Hello, World!")19 obj1.Close()20}21import "fmt"22func main() {23 fmt.Println("Hello, World!")24 obj1.Close()25}26import "fmt"27func main() {28 fmt.Println("Hello, World!")29 obj1.Close()30}31import "fmt"32func main() {33 fmt.Println("Hello, World!")34 obj1.Close()35}36import "fmt"37func main() {38 fmt.Println("Hello, World!")39 obj1.Close()40}41import "fmt"42func main() {43 fmt.Println("Hello, World!")44 obj1.Close()45}

Full Screen

Full Screen

Close

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 c := closer.New("Hello World")4 fmt.Println(c)5 c.Close()6}7import "fmt"8type Closer struct {9}10func New(msg string) *Closer {11 return &Closer{msg}12}13func (c *Closer) Close() {14 fmt.Println("Closing", c.msg)15}16import (17func main() {18 c := closer.Closer{"Hello World"}19 fmt.Println(c)20 c.Close()21}22import "fmt"23type Closer struct {24}25func (c *Closer) Close() {26 fmt.Println("Closing", c.msg)27}28import (29func main() {30 c := closer.Closer{"Hello World"}31 fmt.Println(c)32 c.Close()33}34import "fmt"35type Closer struct {36}37func (c *Closer) Close() {38 fmt.Println("Closing", c.msg)39}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful