|
@@ 313-346 (lines=34) @@
|
| 310 |
|
u"(last (list))", value_error) |
| 311 |
|
|
| 312 |
|
|
| 313 |
|
class AppendTest(PreludeTestCase): |
| 314 |
|
def test_append(self): |
| 315 |
|
expected = List([Integer.fromint(1), Integer.fromint(2)]) |
| 316 |
|
|
| 317 |
|
self.assertEvalsTo( |
| 318 |
|
u"(set-symbol! (quote x) (quote (1))) (append! x 2) x", |
| 319 |
|
expected) |
| 320 |
|
|
| 321 |
|
def test_append_bytestring(self): |
| 322 |
|
self.assertEvalsTo( |
| 323 |
|
u'(set-symbol! (quote x) #bytes("a")) (append! x 98) x', |
| 324 |
|
Bytestring([ord(c) for c in "ab"])) |
| 325 |
|
|
| 326 |
|
def test_append_string(self): |
| 327 |
|
self.assertEvalsTo( |
| 328 |
|
u'(set-symbol! (quote x) "a") (append! x \'b\') x', |
| 329 |
|
String(list(u"ab"))) |
| 330 |
|
|
| 331 |
|
def test_append_returns_null(self): |
| 332 |
|
self.assertEvalsTo( |
| 333 |
|
u"(append! (quote ()) 1)", |
| 334 |
|
NULL) |
| 335 |
|
|
| 336 |
|
def test_append_arg_number(self): |
| 337 |
|
self.assertEvalError( |
| 338 |
|
u"(append! (quote ()))", wrong_argument_number) |
| 339 |
|
|
| 340 |
|
self.assertEvalError( |
| 341 |
|
u"(append! (quote ()) 0 1)", wrong_argument_number) |
| 342 |
|
|
| 343 |
|
def test_append_typeerror(self): |
| 344 |
|
# first argument must be a list |
| 345 |
|
self.assertEvalError( |
| 346 |
|
u"(append! #null 0)", wrong_type) |
| 347 |
|
|
| 348 |
|
|
| 349 |
|
class PushTest(PreludeTestCase): |
|
@@ 349-380 (lines=32) @@
|
| 346 |
|
u"(append! #null 0)", wrong_type) |
| 347 |
|
|
| 348 |
|
|
| 349 |
|
class PushTest(PreludeTestCase): |
| 350 |
|
def test_push_list(self): |
| 351 |
|
expected = List([Integer.fromint(1)]) |
| 352 |
|
self.assertEvalsTo(u"(set-symbol! (quote x) (quote ())) (push! x 1) x", expected) |
| 353 |
|
|
| 354 |
|
def test_push_bytestring(self): |
| 355 |
|
self.assertEvalsTo( |
| 356 |
|
u'(set-symbol! (quote x) #bytes("bc")) (push! x 97) x', |
| 357 |
|
Bytestring([ord(c) for c in b"abc"])) |
| 358 |
|
|
| 359 |
|
def test_push_string(self): |
| 360 |
|
self.assertEvalsTo( |
| 361 |
|
u'(set-symbol! (quote x) "bc") (push! x \'a\') x', |
| 362 |
|
String(list(u"abc"))) |
| 363 |
|
|
| 364 |
|
def test_push_returns_null(self): |
| 365 |
|
self.assertEqual( |
| 366 |
|
evaluate_with_prelude(parse_one(lex( |
| 367 |
|
u"(push! (quote ()) 1)"))), |
| 368 |
|
NULL) |
| 369 |
|
|
| 370 |
|
def test_push_arg_number(self): |
| 371 |
|
self.assertEvalError( |
| 372 |
|
u"(push! (quote ()))", wrong_argument_number) |
| 373 |
|
|
| 374 |
|
self.assertEvalError( |
| 375 |
|
u"(push! (quote ()) 0 1)", wrong_argument_number) |
| 376 |
|
|
| 377 |
|
def test_push_typeerror(self): |
| 378 |
|
# first argument must be a list |
| 379 |
|
self.assertEvalError( |
| 380 |
|
u"(push! #null 0)", wrong_type) |
| 381 |
|
|
| 382 |
|
|
| 383 |
|
class NotTest(PreludeTestCase): |