def test_stroke_fill_mode():
    p = Pen()
    p.set_mode(StrokeFillMode(0.2, 'black', 'red'))
    p.move_to((0, 0))
    p.turn_to(0)
    p.arc_left(180, 5)
    assert_equal(
        p.paper.svg_elements(1)[0],
        (
            '<path d="M0.0,0.0 A 5.0,5.0 0 0 0 0.0,-10.0" fill="#ff0000" />'
            '<path d="M0.0,-0.1 L0.0,0.1 A 5.1,5.1 0 0 0 0.0,-10.1 '
            'L0.0,-9.9 A 4.9,4.9 0 0 1 0.0,-0.1 z" fill="#000000" />'
        )
    )
def test_stroke_fill_mode():
    p = Pen()
    p.set_mode(StrokeFillMode(0.2, 'black', 'red'))
    p.move_to((0, 0))
    p.turn_to(0)
    p.arc_left(180, 5)
    assert_equal(
        p.paper.svg_elements(1)[0],
        (
            '<path d="M0.0,0.0 A 5.0,5.0 0 0 0 0.0,-10.0" fill="#ff0000" />'
            '<path d="M0.0,-0.1 L0.0,0.1 A 5.1,5.1 0 0 0 0.0,-10.1 '
            'L0.0,-9.9 A 4.9,4.9 0 0 1 0.0,-0.1 z" fill="#000000" />'
        )
    )
def test_stroke_outline_mode():
    p = Pen()
    p.set_mode(StrokeOutlineMode(1.0, 0.2, 'red', 'black'))
    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(5)
    assert_equal(
        p.paper.svg_elements(1)[0],
        (
            '<path d="M0.0,-0.5 L0.0,0.5 L5.0,0.5 L5.0,-0.5 L0.0,-0.5 z" '
            'fill="#ff0000" />'
            '<path d="M-0.1,-0.6 L-0.1,0.6 L5.1,0.6 L5.1,-0.6 L-0.1,-0.6 z '
            'M0.1,-0.4 L4.9,-0.4 L4.9,0.4 L0.1,0.4 L0.1,-0.4 z" '
            'fill="#000000" />'
        )
    )
def test_stroke_outline_mode():
    p = Pen()
    p.set_mode(StrokeOutlineMode(1.0, 0.2, 'red', 'black'))
    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(5)
    assert_equal(
        p.paper.svg_elements(1)[0],
        (
            '<path d="M0.0,-0.5 L0.0,0.5 L5.0,0.5 L5.0,-0.5 L0.0,-0.5 z" '
            'fill="#ff0000" />'
            '<path d="M-0.1,-0.6 L-0.1,0.6 L5.1,0.6 L5.1,-0.6 L-0.1,-0.6 z '
            'M0.1,-0.4 L4.9,-0.4 L4.9,0.4 L0.1,0.4 L0.1,-0.4 z" '
            'fill="#000000" />'
        )
    )
def test_save_mode():
    p = Pen()
    p.stroke_mode(2.0, 'red')
    old_mode = p.mode
    p.line_forward(5)
    p.fill_mode('blue')
    p.square(2)
    p.set_mode(old_mode)
    p.line_forward(5)

    assert_path_data(
        p, 0,
        [
            'M0,-1 L0,1 L5,1 L5,-1 L0,-1 z',
            'M4,1 L6,1 L6,-1 L4,-1 L4,1 z',
            'M5,-1 L5,1 L10,1 L10,-1 L5,-1 z',
        ]
    )
def test_save_mode():
    p = Pen()
    p.stroke_mode(2.0, 'red')
    old_mode = p.mode
    p.line_forward(5)
    p.fill_mode('blue')
    p.square(2)
    p.set_mode(old_mode)
    p.line_forward(5)

    assert_path_data(
        p, 0,
        [
            'M0,-1 L0,1 L5,1 L5,-1 L0,-1 z',
            'M4,1 L6,1 L6,-1 L4,-1 L4,1 z',
            'M5,-1 L5,1 L10,1 L10,-1 L5,-1 z',
        ]
    )
def test_outliner_mode():
    # We can set up a pattern in one mode,
    p = Pen()
    p.set_mode(StrokeOutlineMode(sqrt3, 0.2 * sqrt3, 'blue', 'black'))

    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(5, end_slant=60)

    # Then continue it in another mode without caring what the first mode was.
    old_mode = p.mode
    p.set_mode(p.mode.outliner_mode())

    p.turn_to(60)
    p.move_forward(1.0)

    p.turn_left(60)
    p.line_forward(2.0)
    p.turn_right(120)
    p.line_forward(2.0)
    p.turn_right(120)
    p.line_forward(2.0)

    p.turn_to(60)
    p.move_forward(3.0)
    p.turn_to(120)

    p.set_mode(old_mode)

    p.line_forward(5, start_slant=60)

    assert_svg_file(
        p, 3,
        'test_outliner_mode.svg'
    )
def test_outliner_mode():
    # We can set up a pattern in one mode,
    p = Pen()
    p.set_mode(StrokeOutlineMode(sqrt3, 0.2 * sqrt3, 'blue', 'black'))

    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(5, end_slant=60)

    # Then continue it in another mode without caring what the first mode was.
    old_mode = p.mode
    p.set_mode(p.mode.outliner_mode())

    p.turn_to(60)
    p.move_forward(1.0)

    p.turn_left(60)
    p.line_forward(2.0)
    p.turn_right(120)
    p.line_forward(2.0)
    p.turn_right(120)
    p.line_forward(2.0)

    p.turn_to(60)
    p.move_forward(3.0)
    p.turn_to(120)

    p.set_mode(old_mode)

    p.line_forward(5, start_slant=60)

    assert_svg_file(
        p, 3,
        'test_outliner_mode.svg'
    )