Title: IDLE: Improve Mock_Text
Type: enhancement Stage: patch review
Components: IDLE Versions: Python 3.7, Python 3.6
Status: open Resolution:
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: JayKrish, Saimadhav.Heblikar, Todd.Rovito, ezio.melotti, jesstess, philwebster, terry.reedy
Priority: normal Keywords: patch

Created on 2013-07-19 13:00 by JayKrish, last changed 2017-06-19 23:30 by terry.reedy.

File name Uploaded Description Edit
decodeChecklist.txt JayKrish, 2013-07-19 13:02 JayKrish, 2013-07-19 13:04
mocktk_decodeByRE1.patch JayKrish, 2013-07-26 20:35 review
mock-text-_decode.diff Saimadhav.Heblikar, 2014-06-01 14:44 review
Messages (4)
msg193358 - (view) Author: R. Jayakrishnan (JayKrish) * Date: 2013-07-19 13:00
Following the Idle: mock Text class and test thereof created #18365
I am trying to improve the _decode function because most of the Idletests needs the mock text and requires some more features to handle indexes.
Started improving the mockText _decode method while writing unit test for at #18292. 
For now I want the mock text to decode following indexes: 
line.char, insert, end, +-#c/chars, lineend, linestart, wordstart, wordend

For this I am trying to write regular expressions to extract the parts of index.
The submitted is a sample script to show how my regular expression starts manipulating the decoding of indexes.

I have attached a checklist of several indexes. So you can easily run them and get an understanding of my approach.
msg193395 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-07-20 02:31
Further changes should be aimed at actual idlelib uses. Wordstart and wordend are used once each in (and wordstart a couple of times for tag.start positions). So forget them.

Does idlelib really have indexes like "2.3 + 1c" ('2.4'), "2.3-1c" ('2.2'), and "22.33-1chars" ('22.32')?

The grammar we need to parse is something like
index := base modifier*  # nearly always 0, 1, few 2, one 3 times, so
index := base modifier{0:3}
index := base modmaybe modmaybe modmaybe
base := numpair | mark
numpair := int '.' ( int | 'end' )
mark := 'end' | 'insert' | 'iomark' | 'my_anchor'
      | 'sel.first' | sel.last  # parts tags but this should work
modmaybe := modifier | ''
modifier := ' linestart' | ' lineend' | incr
incr := ' '* ('+' | '-') ' '* int ('c' | 'line')
  # Could change the one 'char' to 'c'

Rather than parse an entire index at once, parse, interpret as position, and remove base from input. While remainder, parse, apply to position, and remove from remainder. Whether the parsing is done with base and modifier REs with groups or code or some mixture does not much matter.
msg193740 - (view) Author: R. Jayakrishnan (JayKrish) * Date: 2013-07-26 20:35
Yes,correcting myself. I should aim indexes which actual idlelib uses. Thank you Terry for the grammar. Fighting with the index parsing last week, and finally came up with a level to break the index into base and modifier and decode it along with using regular expressions.
Now the mock_tk attached at this patch passes all the existing test cases, and failing the new test I have written on text_test

The problem now I am dealing with is, there are four exceeding conditions I have to handle which make errors.
1.returning line  < 0
2.returning line  > last line
3.returning char  < 0 
4.returning char > its line length

For example, in parsing base the return line may exceed last line but the modifier will say '-2lines'  doing that, now the return line is not exceeding last line.
msg219502 - (view) Author: Saimadhav Heblikar (Saimadhav.Heblikar) * Date: 2014-06-01 14:44
This patch tries to enable mock_Tk.Text._decode to handle the following patterns
insert linestart
insert lineend
insert wordstart
insert wordend
insert +x chars
insert -x chars

These additions are required for testing AutoExpand and are written keeping the same in mind. Also, adds respective tests for test_decode in

I would like to know if my approach is acceptable or whether it needs changes.

issue18292 is about adding unittests for AutoExpand.

(A 2.7 patch will be submitted once the above changes become acceptable)
Date User Action Args
2017-06-19 23:30:45terry.reedysettitle: IDLE:Improvements- Improving Mock_Text -> IDLE: Improve Mock_Text
2017-06-19 23:28:16terry.reedysetcomponents: + IDLE
versions: + Python 3.6, Python 3.7, - Python 2.7, Python 3.3, Python 3.4
2014-06-01 14:44:35Saimadhav.Heblikarsetfiles: + mock-text-_decode.diff
nosy: + jesstess, Saimadhav.Heblikar
messages: + msg219502

2013-08-10 14:59:02ezio.melottisetnosy: + ezio.melotti

stage: test needed -> patch review
2013-07-26 20:35:42JayKrishsetfiles: + mocktk_decodeByRE1.patch
keywords: + patch
messages: + msg193740
2013-07-23 03:11:05JayKrishsetnosy: + Todd.Rovito
2013-07-23 03:09:20philwebstersetnosy: + philwebster
2013-07-20 02:31:42terry.reedysetassignee: terry.reedy
type: enhancement
versions: + Python 2.7, Python 3.3, Python 3.4
nosy: + terry.reedy

messages: + msg193395
stage: test needed
2013-07-19 13:04:43JayKrishsetfiles: +
2013-07-19 13:04:12JayKrishsetfiles: -
2013-07-19 13:02:01JayKrishsetfiles: + decodeChecklist.txt
2013-07-19 13:00:52JayKrishcreate