Changeset 5330:80b6df59d3fc in livinglogic.python.xist

Show
Ignore:
Timestamp:
02/09/13 20:49:08 (7 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Add list methods append, insert and pop.

Files:
3 modified

Legend:

Unmodified
Added
Removed
  • NEWS.rst

    r5325 r5330  
    2727*   The UL4 methods ``days``, ``seconds``, ``microseconds`` and ``months`` have 
    2828    been added for ``timedelta``/``monthdelta`` objects. 
     29 
     30*   Lists in UL4 now support the methods ``append``, ``insert`` and ``pop``. 
    2931 
    3032*   The UL4 functions ``vars`` and ``get`` have been removed. 
  • src/ll/ul4c.py

    r5329 r5330  
    33653365 
    33663366 
     3367@AST.makemethod 
     3368def _append(obj, item): 
     3369    return obj.append(item) 
     3370 
     3371 
     3372@AST.makemethod 
     3373def _insert(obj, pos, item): 
     3374    return obj.insert(pos, item) 
     3375 
     3376 
     3377@AST.makemethod 
     3378def _pop(obj, pos=-1): 
     3379    return obj.pop(pos) 
     3380 
     3381 
    33673382class TemplateClosure(Object): 
    33683383    fields = {"location", "endlocation", "name", "source", "startdelim", "enddelim", "content"} 
  • test/test_ul4.py

    r5328 r5330  
    30233023def test_method_months(r): 
    30243024    assert '17' == r('<?print monthdelta(17).months()?>') 
     3025 
     3026 
     3027@pytest.mark.ul4 
     3028def test_method_append(r): 
     3029    assert '42' == r('<?code l = []?><?code l.append(42)?><?print l[0]?>') 
     3030 
     3031 
     3032@pytest.mark.ul4 
     3033def test_method_insert(r): 
     3034    assert '17;23;42;' == r('<?code l = []?><?code l.insert(0, 42)?><?code l.insert(0, 17)?><?code l.insert(1, 23)?><?print l[0]?>;<?print l[1]?>;<?print l[2]?>;') 
     3035 
     3036 
     3037@pytest.mark.ul4 
     3038def test_method_pop(r): 
     3039    assert '42;17;23;' == r('<?code l = [17, 23, 42]?><?print l.pop()?>;<?print l.pop(-2)?>;<?print l.pop(0)?>;') 
    30253040 
    30263041