3
2a8 @ s d dl mZ d dlZd dlmZ d dlmZmZ d dl m
Z
G dd dejZG dd d ejZ
G d
d dejZG dd
d
ejZG dd dejZG dd dZG dd dZG dd dejZedkrejddd dS ) ) paragraphN)requires)TkText)EditorWindowc @ s8 e Zd ZdZdZdZdZdZdd Zdd Z d
d Z
dS )
Is_Get_Testz# This is a commentzThis is not a commentz# This is a comment z # This is a commentz This is not a commentc C s6 | j tjd | j tjd | jtj| j d S )N z
)Z
assertTruepgZis_all_whiteZassertFalsetest_comment)self r 3/opt/alt/python36/lib64/python3.6/test_paragraph.pytest_is_all_white s zIs_Get_Test.test_is_all_whitec C sR | j }|tj| jd |tj| jd |tj| jd |tj| jd d S )Nr z )assertEqualr Z
get_indentr
trailingws_commentleadingws_commentleadingws_nocomment)r Equalr r r
test_get_indent s
zIs_Get_Test.test_get_indentc C sd | j }|tj| jd |tj| jd |tj| jd |tj| jd |tj| jd d S )N#z #z r )r r Zget_comment_headerr
r r r test_nocomment)r r r r r
test_get_comment_header s z#Is_Get_Test.test_get_comment_headerN)__name__
__module____qualname__r
r r r r r r r r r r r
r
s r c @ s0 e Zd Zedd Zdd Zdd Zdd Zd S )
FindTestc C s ddl m} | | _d S )Nr )r )Zidlelib.idle_test.mock_tkr text)clsr r r r
setUpClass3 s zFindTest.setUpClassc C s | j }|jd| xftd|D ]X}t|jd| jdd }x6d|d |fD ]$}d||f }| jtj||| qNW qW |j dd d S ) Nz1.0 z%d.end.r z%d.%dend)
r insertrangeintindexsplitr r Zfind_paragraphdelete) r Z
inserttextZstoplineexpectedr lineZ
linelengthcolZ tempindexr r r
runcase8 s zFindTest.runcasec C s d}| j |dddd|dd f d}| j |d d
dd|dd
f d}| j |d d
dd|dd f d}| j |dd
dd|dd f d}| j |dd
dd|dd f d}| j |dd
dd|dd f d}| j |dd
dd|dd f d}| j |dd
dd|dd f d S )Nz;# Comment block with no blank lines before
# Comment line
z1.0z3.0r r : zG
# Comment block with whitespace line before and after
# Comment line
z2.0z4.0r F zS
# Indented comment block with whitespace before and after
# Comment line
z #R z
# Single line comment
z4
# Single line comment with leading whitespace
3 z0
# Comment immediately followed by code
x = 42
( z=
# Indented comment immediately followed by code
x = 42
5 z=
# Comment immediately followed by indented code
x = 42
1 )r, )r Zcommentr r r
test_find_commentE s zFindTest.test_find_commentc C s d}| j |dddd|dd f d}| j |d d
dd|dd
f d}| j |d d
dd|dd f d}| j |dd
dd|dd f d}| j |dd
dd|dd f d S )Nz6"""String with no blank lines before
String line
"""
r/ z1.0z4.0r r r5 zC
"""String with whitespace line before and after
String line.
"""
z2.0z5.0r B zV
"""Indented string with whitespace before and after
Comment string.
"""
z U z
"""Single line string."""
r- z3.0 z8
"""Single line string with leading whitespace."""
7 )r, )r Z
teststringr r r
test_find_paragraph{ s zFindTest.test_find_paragraphN)r r r classmethodr r, r7 r= r r r r
r ) s
6r c @ s e Zd Zdd ZdS )ReformatFunctionTestc C s | j }tj}d}||ddd ||ddd |||dd |||dd |||d d
|||dd
|||dd d
}|||dd |||dd |||d d |||dd |||dd
d S )Nz
O hello world r zHello world zHello worldz
O
hello
world z
O hello
world
z
O hello worldz
O
hello
worldz
O hello
world)r r Zreformat_paragraph)r r ZreformZhwr r r
test_reformat_paragraph s z,ReformatFunctionTest.test_reformat_paragraphN)r r r rF r r r r
r? s r? c @ s e Zd Zdd ZdS )ReformatCommentTestc C sJ | j }d}tj|dd}d}||| d}tj|dd}d}||| d S )Nzu """this is a test of a reformat for a triple quoted string will it reformat to less than 70 characters for me?"""r0 z zy """this is a test of a reformat for a triple quoted string will it
reformat to less than 70 characters for me?"""zm# this is a test of a reformat for a triple quoted string will it reformat to less than 70 characters for me?r zo# this is a test of a reformat for a triple quoted string will it
# reformat to less than 70 characters for me?)r r Zreformat_comment)r r test_stringresultr) r
r r r
test_reformat_comment s
z)ReformatCommentTest.test_reformat_commentN)r r r rJ r r r r
rG s rG c @ s e Zd Zdd ZdS )FormatClassTestc C s2 t jd}| j|jd |j | j|jd d S )Neditor)r FormatParagraphr Zeditwinclose)r instancer r r
test_init_close s
zFormatClassTest.test_init_closeN)r r r rP r r r r
rK s rK c @ s, e Zd Zdd Zdd Zdd Zdd Zd S )
TextWrapperc C s t |d| _d S )N)master)r r )r rR r r r
__init__ s zTextWrapper.__init__c C s t | j|S )N)getattrr )r namer r r
__getattr__ s zTextWrapper.__getattr__c C s d S )Nr )r r r r
undo_block_start s zTextWrapper.undo_block_startc C s d S )Nr )r r r r
undo_block_stop s zTextWrapper.undo_block_stopN)r r r rS rV rW rX r r r r
rQ s rQ c @ s e Zd Zdd ZejZdS )Editorc C s t || _d S )N)rQ r )r rootr r r
rS s zEditor.__init__N)r r r rS r Zget_selection_indicesr r r r
rY s rY c @ sP e Zd ZdZdZdZedd Zedd Zdd Z d
d Z
dd
Zdd ZdS )FormatEventTestzv '''this is a test of a reformat for a triple quoted string will it reformat to less than 70 characters for me?'''
a '''The first line is under the max width.
The second line's length is way over the max width. It goes on and on until it is over 100 characters long.
Same thing with the third line. It is also way over the max width, but FormatParagraph will fix it.
'''
a, # The first line is under the max width.
# The second line's length is way over the max width. It goes on and on until it is over 100 characters long.
# Same thing with the third line. It is also way over the max width, but FormatParagraph will fix it.
# The fourth line is short like the first line.c C sB t d t | _| jj t| jd}|jj| _tj|j| _ d S )NZgui)rZ )
r r rZ ZwithdrawrY r r rM Zformat_paragraph_event formatter)r rL r r r
r
s
zFormatEventTest.setUpClassc C s$ | ` | `| jj | jj | `d S )N)r r\ rZ Zupdate_idletasksZdestroy)r r r r
tearDownClass s
zFormatEventTest.tearDownClassc C s@ | j jdd | jd | j| j jddd | j jdd d S )Nz1.0zShort line
ZDummyr# r" )r r# r\ r getr( )r r r r
test_short_line s
zFormatEventTest.test_short_linec C s | j }|jd| j |jdd | jddd |jdd}d}| j|| |jdd |jd| j |jdd d
| jddd |jdd}d}| j|| |jdd d S )Nz1.0r# ParameterDoesNothingr0 )limitzz '''this is a test of a reformat for a triple quoted string will it
reformat to less than 70 characters for me?'''
r" selz1.11z1.endzv '''this is a test of a reformat for a triple quoted string will it reformat
to less than 70 characters for me?''') r r# rH Zmark_setr\ r^ r r( tag_add)r r rI r) r r r
test_long_line$ s zFormatEventTest.test_long_linec C s\ | j }|jd| j |jddd | jddd |jdd}d }| j|| |jdd
d S )Nz1.0rb z2.0z4.0r` r0 )ra r# z The second line's length is way over the max width. It goes on and
on until it is over 100 characters long. Same thing with the third
line. It is also way over the max width, but FormatParagraph will
fix it.
r" )r r# multiline_test_stringrc r\ r^ r r( )r r rI r) r r r
test_multiple_lines? s z#FormatEventTest.test_multiple_linesc C s | j }|jd| j | jddd |jdd}d}| j|| |jdd |jd| j |jdd d
| jddd |jdd}d}| j|| |jdd d S )Nz1.0r` r0 )ra r# a/ # The first line is under the max width. The second line's length is
# way over the max width. It goes on and on until it is over 100
# characters long. Same thing with the third line. It is also way over
# the max width, but FormatParagraph will fix it. The fourth line is
# short like the first line.
r" rb z2.0z3.0z# The first line is under the max width.
# The second line's length is way over the max width. It goes on and
# on until it is over 100 characters long.
)r r# multiline_test_commentr\ r^ r r( rc )r r rI r) r r r
test_comment_blockN s z"FormatEventTest.test_comment_blockN)
r r r rH re rg r> r r] r_ rd rf rh r r r r
r[ s
r[ __main__r! ) verbosityexit)Zidlelibr r ZunittestZtest.supportr Ztkinterr r Zidlelib.editorr ZTestCaser r r? rG rK rQ rY r[ r mainr r r r