parser_test.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. package parser
  2. import (
  3. "fmt"
  4. "github/runnignwater/monkey/ast"
  5. "github/runnignwater/monkey/lexer"
  6. "log"
  7. "testing"
  8. )
  9. /**
  10. * @Author: simon
  11. * @Author: ynwdlxm@163.com
  12. * @Date: 2022/10/2 下午10:40
  13. * @Desc: LetStatement test case
  14. */
  15. func TestLetStatements(t *testing.T) {
  16. input := `
  17. let x = 5;
  18. let y = 10;
  19. let foo = 838383;
  20. `
  21. l := lexer.New(input)
  22. p := New(l)
  23. program := p.ParseProgram()
  24. checkParseErrors(t, p)
  25. if program == nil {
  26. t.Fatalf("ParseProgram() return nil")
  27. }
  28. if len(program.Statements) != 3 {
  29. t.Fatalf("Program.Statements does not contain 3 statements. got=%d", len(program.Statements))
  30. }
  31. tests := []struct {
  32. expectedIdentifies string
  33. }{
  34. {"x"},
  35. {"y"},
  36. {"foo"},
  37. }
  38. for i, tt := range tests {
  39. stmt := program.Statements[i]
  40. if !testLetStatement(t, stmt, tt.expectedIdentifies) {
  41. return
  42. }
  43. }
  44. }
  45. func TestReturnStatements(t *testing.T) {
  46. input := `
  47. return 5;
  48. return 10;
  49. return add(a,10);
  50. `
  51. l := lexer.New(input)
  52. p := New(l)
  53. program := p.ParseProgram()
  54. checkParseErrors(t, p)
  55. if len(program.Statements) != 3 {
  56. t.Fatalf("Program.Statements does not contain 3 statements. got=%d", len(program.Statements))
  57. }
  58. for _, stmt := range program.Statements {
  59. returnStmt, ok := stmt.(*ast.ReturnStatement)
  60. if !ok {
  61. t.Errorf("stmt not *ast.ReturnStatement. got=%T", stmt)
  62. continue
  63. }
  64. if returnStmt.TokenLiteral() != "return" {
  65. t.Errorf("returnStmt.TokenLiteral not 'return', got %q", returnStmt.TokenLiteral())
  66. }
  67. }
  68. }
  69. func checkParseErrors(t *testing.T, p *Parser) {
  70. errors := p.errors
  71. if len(errors) == 0 {
  72. return
  73. }
  74. t.Errorf("parse has %d errors.", len(errors))
  75. for _, msg := range errors {
  76. t.Errorf("parse error: %q", msg)
  77. }
  78. t.FailNow()
  79. }
  80. func testLetStatement(t *testing.T, s ast.Statement, name string) bool {
  81. if s.TokenLiteral() != "let" {
  82. t.Errorf("s.TokenLiteral() not 'let'. got =%q", s.TokenLiteral())
  83. return false
  84. }
  85. letStmt, ok := s.(*ast.LetStatement)
  86. if !ok {
  87. t.Errorf("s is not *ast.LetStatement. got=%T", s)
  88. return false
  89. }
  90. if letStmt.Name.Value != name {
  91. t.Errorf("letStmt.Name.Value not '%s'. got=%s", name, letStmt.Name.Value)
  92. return false
  93. }
  94. if letStmt.Name.TokenLiteral() != name {
  95. t.Errorf("s.name not '%s. got=%s", name, letStmt.Name)
  96. return false
  97. }
  98. return true
  99. }
  100. func TestIdentifier(t *testing.T) {
  101. input := "foobar;"
  102. l := lexer.New(input)
  103. p := New(l)
  104. program := p.ParseProgram()
  105. checkParseErrors(t, p)
  106. if len(program.Statements) != 1 {
  107. t.Fatalf("program has not enough statements. got=%d", len(program.Statements))
  108. }
  109. stmt, ok := program.Statements[0].(*ast.ExpressionStatement)
  110. if !ok {
  111. t.Fatalf("program.Statements[0] is not ast.ExpressionStatement. got=%T",
  112. program.Statements[0])
  113. }
  114. ident, ok := stmt.Expression.(*ast.Identifier)
  115. if !ok {
  116. t.Fatalf("exp not *ast.Identifier. got=%T", stmt.Expression)
  117. }
  118. if ident.Value != "foobar" {
  119. t.Fatalf("ident.Value not %s. got=%s", "foobar", ident.Value)
  120. }
  121. if ident.TokenLiteral() != "foobar" {
  122. t.Errorf("ident.TokenLiteral() not %s. got=%s", "foobar", ident.TokenLiteral())
  123. }
  124. }
  125. func TestIntegerLiteralExpression(t *testing.T) {
  126. input := "5;"
  127. l := lexer.New(input)
  128. p := New(l)
  129. program := p.ParseProgram()
  130. checkParseErrors(t, p)
  131. if len(program.Statements) != 1 {
  132. t.Fatalf("program has not enough statements. got=%d",
  133. len(program.Statements))
  134. }
  135. stmt, ok := program.Statements[0].(*ast.ExpressionStatement)
  136. if !ok {
  137. t.Fatalf("program.Statements[0] is not ast.ExpressionStatement. got=%T",
  138. program.Statements[0])
  139. }
  140. literal, ok := stmt.Expression.(*ast.IntegerLiteral)
  141. if !ok {
  142. t.Fatalf("exp not *ast.IntegerLiteral. got=%T", stmt.Expression)
  143. }
  144. if literal.Value != 5 {
  145. t.Errorf("literal.Value not %d. got=%d", 5, literal.Value)
  146. }
  147. if literal.TokenLiteral() != "5" {
  148. t.Errorf("literal.TokenLiteral not %s. got=%s", "5",
  149. literal.TokenLiteral())
  150. }
  151. }
  152. /**
  153. * Prefix Operators or "prefix expressions"
  154. * <prefix operator><expression>;
  155. * -5;
  156. * !foobar;
  157. * 5 + -10;
  158. */
  159. func TestParsingPrefixExpressions(t *testing.T) {
  160. prefixTests := []struct {
  161. input string
  162. operator string
  163. integerValue int64
  164. }{
  165. {"!5;", "!", 5},
  166. {"-15;", "-", 15},
  167. }
  168. for _, tt := range prefixTests {
  169. l := lexer.New(tt.input)
  170. p := New(l)
  171. program := p.ParseProgram()
  172. checkParseErrors(t, p)
  173. if len(program.Statements) != 1 {
  174. t.Fatalf("program.Statement does not contain %d statements. got=%d\n",
  175. 1, len(program.Statements))
  176. }
  177. stmt, ok := program.Statements[0].(*ast.ExpressionStatement)
  178. if !ok {
  179. t.Fatalf("program.Statements[0] is not ast.ExpressionStatement. got=%T",
  180. program.Statements[0])
  181. }
  182. exp, ok := stmt.Expression.(*ast.PrefixExpression)
  183. if !ok {
  184. log.Fatalf("stmt is not ast.PrefixExpression. got=%T", stmt.Expression)
  185. }
  186. if exp.Operator != tt.operator {
  187. t.Fatalf("exp.Operator is not '%s'. got=%s",
  188. tt.operator, exp.Operator)
  189. }
  190. if !testIntegerLiteral(t, exp.Right, tt.integerValue) {
  191. return
  192. }
  193. }
  194. }
  195. func testIntegerLiteral(t *testing.T, il ast.Expression, value int64) bool {
  196. integ, ok := il.(*ast.IntegerLiteral)
  197. if !ok {
  198. t.Errorf("il not *ast.IntegerLiteral. got=%T", il)
  199. return false
  200. }
  201. if integ.Value != value {
  202. t.Errorf("integ.Value not %d. get=%d", value, integ.Value)
  203. return false
  204. }
  205. if integ.TokenLiteral() != fmt.Sprintf("%d", value) {
  206. t.Errorf("integ.TokenLiteral not %d. got=%s", value, integ.TokenLiteral())
  207. return false
  208. }
  209. return true
  210. }
  211. func testLiteralExpression(t *testing.T, exp ast.Expression, expected interface{}) bool {
  212. switch v := expected.(type) {
  213. case int:
  214. return testIntegerLiteral(t, exp, int64(v))
  215. case int64:
  216. return testIntegerLiteral(t, exp, v)
  217. case string:
  218. return testIdentifier(t, exp, v)
  219. case bool:
  220. return testBooleanLiteral(t, exp, v)
  221. }
  222. t.Errorf("type of exp not hand. got=%T", exp)
  223. return false
  224. }
  225. func testBooleanLiteral(t *testing.T, exp ast.Expression, value bool) bool {
  226. bo, ok := exp.(*ast.Boolean)
  227. if !ok {
  228. t.Errorf("exp not *ast.Boolean. got=%T", exp)
  229. return false
  230. }
  231. if bo.Value != value {
  232. t.Errorf("bo.Value not %t. got=%t", value, bo.Value)
  233. return false
  234. }
  235. if bo.TokenLiteral() != fmt.Sprintf("%t", value) {
  236. t.Errorf("bo.TokenLiteral not %t. got=%s", value, bo.TokenLiteral())
  237. return false
  238. }
  239. return true
  240. }
  241. func testIdentifier(t *testing.T, exp ast.Expression, v string) bool {
  242. ident, ok := exp.(*ast.Identifier)
  243. if !ok {
  244. t.Errorf("exp not *ast.Identifier. got=%T", exp)
  245. return false
  246. }
  247. if ident.Value != v {
  248. t.Errorf("ident.Value not %s. got=%s", v, ident.Value)
  249. return false
  250. }
  251. if ident.TokenLiteral() != v {
  252. t.Errorf("ident.TokenLiteral not %s. got=%s", v,
  253. ident.TokenLiteral())
  254. return false
  255. }
  256. return true
  257. }
  258. // <expression> <infix operator> <expression>
  259. func TestParsingInfixExpressions(t *testing.T) {
  260. infixTests := []struct {
  261. input string
  262. leftValue int64
  263. operator string
  264. rightValue int64
  265. }{
  266. {"5 + 5", 5, "+", 5},
  267. {"5 - 5", 5, "-", 5},
  268. {"5 * 5", 5, "*", 5},
  269. {"5 / 5", 5, "/", 5},
  270. {"5 > 5", 5, ">", 5},
  271. {"5 < 5", 5, "<", 5},
  272. {"5 == 5", 5, "==", 5},
  273. {"5 != 5", 5, "!=", 5},
  274. }
  275. for _, tt := range infixTests {
  276. l := lexer.New(tt.input)
  277. p := New(l)
  278. program := p.ParseProgram()
  279. checkParseErrors(t, p)
  280. if len(program.Statements) != 1 {
  281. t.Fatalf("program.Statements does not contain %d statements. got=%d\n",
  282. 1, len(program.Statements))
  283. }
  284. stmt, ok := program.Statements[0].(*ast.ExpressionStatement)
  285. if !ok {
  286. t.Fatalf("program.Statements[0] is not ast.ExpressionStatement. got=%T",
  287. program.Statements[0])
  288. }
  289. exp, ok := stmt.Expression.(*ast.InfixExpression)
  290. if !ok {
  291. t.Fatalf("exp is not ast.InfixExpression. got =%T", stmt.Expression)
  292. }
  293. if !testIntegerLiteral(t, exp.Left, tt.leftValue) {
  294. return
  295. }
  296. if exp.Operator != tt.operator {
  297. t.Fatalf("exp.Operator is not '%s'. got=%s", tt.operator, exp.Operator)
  298. }
  299. if !testIntegerLiteral(t, exp.Right, tt.rightValue) {
  300. return
  301. }
  302. }
  303. }
  304. func TestOperatorPrecedenceParsing(t *testing.T) {
  305. tests := []struct {
  306. input string
  307. expected string
  308. }{
  309. {
  310. "-a * b",
  311. "((-a) * b)",
  312. },
  313. {
  314. "!-a",
  315. "(!(-a))",
  316. },
  317. {
  318. "a + b + c",
  319. "((a + b) + c)",
  320. },
  321. {
  322. "a + b - c",
  323. "((a + b) - c)",
  324. },
  325. {
  326. "a * b * c",
  327. "((a * b) * c)",
  328. },
  329. {
  330. "a * b / c",
  331. "((a * b) / c)",
  332. },
  333. {
  334. "a + b / c",
  335. "(a + (b / c))",
  336. },
  337. {
  338. "a + b * c + d / e - f",
  339. "(((a + (b * c)) + (d / e)) - f)",
  340. },
  341. {
  342. "3 + 4; -5 *5",
  343. "(3 + 4)((-5) * 5)",
  344. },
  345. {
  346. "5 > 4 == 3 < 4",
  347. "((5 > 4) == (3 < 4))",
  348. },
  349. {
  350. "5 < 4 != 3 > 4",
  351. "((5 < 4) != (3 > 4))",
  352. },
  353. {
  354. "3 + 4 * 5 == 3 * 1 + 4 * 5",
  355. "((3 + (4 * 5)) == ((3 * 1) + (4 * 5)))",
  356. },
  357. {
  358. "3 + 4 * 5 == 3 * 1 + 4 * 5",
  359. "((3 + (4 * 5)) == ((3 * 1) + (4 * 5)))",
  360. },
  361. {
  362. "3 > 5 == false",
  363. "((3 > 5) == false)",
  364. },
  365. {
  366. "1 + (2 + 3) + 4",
  367. "((1 + (2 + 3)) + 4)",
  368. },
  369. {
  370. "(5 + 5) * 2",
  371. "((5 + 5) * 2)",
  372. },
  373. {
  374. "2 / (5 + 5)",
  375. "(2 / (5 + 5))"},
  376. {
  377. "-(5 + 5)",
  378. "(-(5 + 5))"},
  379. {
  380. "!(true == true)", "(!(true == true))",
  381. },
  382. }
  383. for _, tt := range tests {
  384. fmt.Printf("=====================================parse %s, begin============================\n", tt.input)
  385. l := lexer.New(tt.input)
  386. p := New(l)
  387. program := p.ParseProgram()
  388. checkParseErrors(t, p)
  389. actual := program.String()
  390. if actual != tt.expected {
  391. t.Errorf("exptected=%q, got=%q", tt.expected, actual)
  392. }
  393. fmt.Printf("=====================================parse %s, end============================\n", tt.input)
  394. }
  395. }
  396. func TestBooleanExpression(t *testing.T) {
  397. tests := []struct {
  398. input string
  399. expectedBoolean bool
  400. }{
  401. {"true;", true},
  402. {"false;", false},
  403. }
  404. for _, tt := range tests {
  405. l := lexer.New(tt.input)
  406. p := New(l)
  407. program := p.ParseProgram()
  408. checkParseErrors(t, p)
  409. if len(program.Statements) != 1 {
  410. t.Fatalf("program has not enough statements. got=%d",
  411. len(program.Statements))
  412. }
  413. stmt, ok := program.Statements[0].(*ast.ExpressionStatement)
  414. if !ok {
  415. t.Fatalf("program.Statements[0] is not ast.ExpressionStatement. got=%T",
  416. program.Statements[0])
  417. }
  418. boolean, ok := stmt.Expression.(*ast.Boolean)
  419. if !ok {
  420. t.Fatalf("exp not *ast.Boolean. got=%T", stmt.Expression)
  421. }
  422. if boolean.Value != tt.expectedBoolean {
  423. t.Errorf("boolean.Value not %t. got=%t", tt.expectedBoolean,
  424. boolean.Value)
  425. }
  426. }
  427. }
  428. func TestIfExpression(t *testing.T) {
  429. input := `if (x < y) { x }`
  430. l := lexer.New(input)
  431. p := New(l)
  432. program := p.ParseProgram()
  433. checkParseErrors(t, p)
  434. if len(program.Statements) != 1 {
  435. t.Fatalf("program.Body does not contain %d statements. got=%d\n",
  436. 1, len(program.Statements))
  437. }
  438. stmt, ok := program.Statements[0].(*ast.ExpressionStatement)
  439. if !ok {
  440. t.Fatalf("program.Statements[0] is not ast.ExpressionStatement. got=%T", program.Statements[0])
  441. }
  442. exp, ok := stmt.Expression.(*ast.IfExpression)
  443. if !ok {
  444. t.Fatalf("stmt.Expression is not ast.IfExpression. got=%T", stmt.Expression)
  445. }
  446. if !testInfixExpression(t, exp.Condition, "x", "<", "y") {
  447. return
  448. }
  449. if len(exp.Consequence.Statements) != 1 {
  450. t.Errorf("consequence is not 1 statements. got=%d\n",
  451. len(exp.Consequence.Statements))
  452. }
  453. consequence, ok := exp.Consequence.Statements[0].(*ast.ExpressionStatement)
  454. if !ok {
  455. t.Fatalf("Statements[0] is not ast.ExpressionStatement. got=%T", exp.Consequence.Statements[0])
  456. }
  457. if !testIdentifier(t, consequence.Expression, "x") {
  458. return
  459. }
  460. if exp.Alternative != nil {
  461. t.Errorf("exp.Alternative.Statements was not nil. got=%+v", exp.Alternative)
  462. }
  463. }
  464. func TestIfElseExpression(t *testing.T) {
  465. input := `if (x < y) { x } else { y }`
  466. l := lexer.New(input)
  467. p := New(l)
  468. program := p.ParseProgram()
  469. checkParseErrors(t, p)
  470. if len(program.Statements) != 1 {
  471. t.Fatalf("program.Body does not contain %d statements. got=%d\n",
  472. 1, len(program.Statements))
  473. }
  474. stmt, ok := program.Statements[0].(*ast.ExpressionStatement)
  475. if !ok {
  476. t.Fatalf("program.Statements[0] is not ast.ExpressionStatement. got=%T",
  477. program.Statements[0])
  478. }
  479. exp, ok := stmt.Expression.(*ast.IfExpression)
  480. if !ok {
  481. t.Fatalf("stmt.Expression is not ast.IfExpression. got=%T", stmt.Expression)
  482. }
  483. if !testInfixExpression(t, exp.Condition, "x", "<", "y") {
  484. return
  485. }
  486. if len(exp.Consequence.Statements) != 1 {
  487. t.Errorf("consequence is not 1 statements. got=%d\n",
  488. len(exp.Consequence.Statements))
  489. }
  490. consequence, ok := exp.Consequence.Statements[0].(*ast.ExpressionStatement)
  491. if !ok {
  492. t.Fatalf("Statements[0] is not ast.ExpressionStatement. got=%T",
  493. exp.Consequence.Statements[0])
  494. }
  495. if !testIdentifier(t, consequence.Expression, "x") {
  496. return
  497. }
  498. if len(exp.Alternative.Statements) != 1 {
  499. t.Errorf("exp.Alternative.Statements does not contain 1 statements. got=%d\n",
  500. len(exp.Alternative.Statements))
  501. }
  502. alternative, ok := exp.Alternative.Statements[0].(*ast.ExpressionStatement)
  503. if !ok {
  504. t.Fatalf("Statements[0] is not ast.ExpressionStatement. got=%T",
  505. exp.Alternative.Statements[0])
  506. }
  507. if !testIdentifier(t, alternative.Expression, "y") {
  508. return
  509. }
  510. }
  511. func testInfixExpression(t *testing.T, exp ast.Expression, left interface{},
  512. operator string, right interface{}) bool {
  513. opExp, ok := exp.(*ast.InfixExpression)
  514. if !ok {
  515. t.Errorf("exp is not ast.OperatorExpression. got=%T(%s)", exp, exp)
  516. return false
  517. }
  518. if !testLiteralExpression(t, opExp.Left, left) {
  519. return false
  520. }
  521. if opExp.Operator != operator {
  522. t.Errorf("exp.Operator is not '%s'. got=%q", operator, opExp.Operator)
  523. return false
  524. }
  525. if !testLiteralExpression(t, opExp.Right, right) {
  526. return false
  527. }
  528. return true
  529. }
  530. func TestFunctionLiteral(t *testing.T) {
  531. input := `fn(x,y) {x+y}`
  532. l := lexer.New(input)
  533. p := New(l)
  534. program := p.ParseProgram()
  535. checkParseErrors(t, p)
  536. if len(program.Statements) != 1 {
  537. t.Fatalf("Program.Body does not contain %d statements. got=%d\n", 1, len(program.Statements))
  538. }
  539. stmt, ok := program.Statements[0].(*ast.ExpressionStatement)
  540. if !ok {
  541. t.Fatalf("program.Statement[0] is not ast.ExpressionStatemtn. got=%T", program.Statements[0])
  542. }
  543. function, ok := stmt.Expression.(*ast.FunctionLiteral)
  544. if !ok {
  545. t.Fatalf("stmt.Expression is not ast.FunctionLiteral. got=%T", stmt.Expression)
  546. }
  547. if len(function.Parameters) != 2 {
  548. t.Fatalf("function literal parameters wrong. want 2, got =%d\n", len(function.Parameters))
  549. }
  550. testLiteralExpression(t, function.Parameters[0], "x")
  551. testLiteralExpression(t, function.Parameters[1], "y")
  552. if len(function.Body.Statements) != 1 {
  553. t.Fatalf("function.Body.Statements has not 1 statements. got=%d\n", len(function.Body.Statements))
  554. }
  555. bodyStmt, ok := function.Body.Statements[0].(*ast.ExpressionStatement)
  556. if !ok {
  557. t.Fatalf("function body stmt is not ast.ExpressionStatement. got=%T", function.Body.Statements[0])
  558. }
  559. testInfixExpression(t, bodyStmt.Expression, "x", "+", "y")
  560. }
  561. func TestFunctionParameterParsing(t *testing.T) {
  562. tests := []struct {
  563. input string
  564. expectedParams []string
  565. }{
  566. {input: "fn() {};", expectedParams: []string{}},
  567. {input: "fn(x){};", expectedParams: []string{"x"}},
  568. {input: "fn(x,y,z){};", expectedParams: []string{"x", "y", "z"}},
  569. }
  570. for _, tt := range tests {
  571. l := lexer.New(tt.input)
  572. p := New(l)
  573. program := p.ParseProgram()
  574. checkParseErrors(t, p)
  575. stmt := program.Statements[0].(*ast.ExpressionStatement)
  576. function := stmt.Expression.(*ast.FunctionLiteral)
  577. if len(function.Parameters) != len(tt.expectedParams) {
  578. t.Errorf("length parameters wrong. want %d, got=%d\n",
  579. len(tt.expectedParams), len(function.Parameters))
  580. }
  581. for i, ident := range tt.expectedParams {
  582. testLiteralExpression(t, function.Parameters[i], ident)
  583. }
  584. }
  585. }
  586. func TestCallExpressionParsing(t *testing.T) {
  587. input := `add(1, 2 * 3, 4+5);`
  588. l := lexer.New(input)
  589. p := New(l)
  590. program := p.ParseProgram()
  591. checkParseErrors(t, p)
  592. if len(program.Statements) != 1 {
  593. t.Fatalf("program.Statement does not contain %d statements. got=%d\n", 1, len(program.Statements))
  594. }
  595. stmt, ok := program.Statements[0].(*ast.ExpressionStatement)
  596. if !ok {
  597. t.Fatalf("stmt is not ast.ExpressionStatement. got=%T", program.Statements[0])
  598. }
  599. exp, ok := stmt.Expression.(*ast.CallExpression)
  600. if !ok {
  601. t.Fatalf("stmt.Expression is not ast.CallExpression. got=%T", stmt.Expression)
  602. }
  603. if !testIdentifier(t, exp.Function, "add") {
  604. return
  605. }
  606. if len(exp.Arguments) != 3 {
  607. t.Fatalf("wrong length arguments. got=%d", len(exp.Arguments))
  608. }
  609. testLiteralExpression(t, exp.Arguments[0], 1)
  610. testInfixExpression(t, exp.Arguments[1], 2, "*", 3)
  611. testInfixExpression(t, exp.Arguments[2], 4, "+", 5)
  612. }