summary refs log blame commit diff stats
path: root/doc/pydoc/all_tests.html
blob: 5d206fa822f6f51b0a2a118fce8232936a5db114 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14













                                                                                                                                                                                         
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module all_tests</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head><body bgcolor="#f0f0f8">

<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong>all_tests</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/hut/work/ranger/all_tests.py">/home/hut/work/ranger/all_tests.py</a></font></td></tr></table>
    <p><tt>Run&nbsp;all&nbsp;the&nbsp;tests&nbsp;inside&nbsp;the&nbsp;test/&nbsp;directory&nbsp;as&nbsp;a&nbsp;test&nbsp;suite.</tt></p>

</body></html>
Agaram <vc@akkartik.com> 2022-06-02 17:46:30 -0700 committer Kartik K. Agaram <vc@akkartik.com> 2022-06-02 17:46:30 -0700 more efficient undo/redo' href='/akkartik/text.love/commit/undo.lua?id=4f76ea37d7a24e6562fb8640935750c50de62e69'>4f76ea3 ^
5b91af1 ^
6708862 ^






4ce716f ^

6708862 ^







4f76ea3 ^

















29dac6a ^










6708862 ^











4f76ea3 ^



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124







                                                                                      




                                            


     




                                                        



                 




                                                        



                 
                                  
                                                                                                               
                             
                                                             

                  

         
                          
                         
                                               
                         
                                               

                                        


                                           
                                      
                                                      
             

                 


                                                                 
              
                               






                                                                                    

                                                                                                                                       







                      

















                                                       










                                                   











                                                                                                    



                                     
-- undo/redo by managing the sequence of events in the current session
-- based on https://github.com/akkartik/mu1/blob/master/edit/012-editor-undo.mu

-- Incredibly inefficient; we make a copy of lines on every single keystroke.
-- The hope here is that we're either editing small files or just reading large files.
-- TODO: highlight stuff inserted by any undo/redo operation
-- TODO: coalesce multiple similar operations

function record_undo_event(State, data)
  State.history[State.next_history] = data
  State.next_history = State.next_history+1
  for i=State.next_history,#State.history do
    State.history[i] = nil
  end
end

function undo_event(State)
  if State.next_history > 1 then
--?     print('moving to history', State.next_history-1)
    State.next_history = State.next_history-1
    local result = State.history[State.next_history]
    return result
  end
end

function redo_event(State)
  if State.next_history <= #State.history then
--?     print('restoring history', State.next_history+1)
    local result = State.history[State.next_history]
    State.next_history = State.next_history+1
    return result
  end
end

-- Copy all relevant global state.
-- Make copies of objects; the rest of the app may mutate them in place, but undo requires immutable histories.
function snapshot(State, s,e)
  -- Snapshot everything by default, but subset if requested.
  assert(s)
  if e == nil then
    e = s
  end
  assert(#State.lines > 0)
  if s < 1 then s = 1 end
  if s > #State.lines then s = #State.lines end
  if e < 1 then e = 1 end
  if e > #State.lines then e = #State.lines end
  -- compare with App.initialize_globals
  local event = {
    screen_top=deepcopy(State.screen_top1),
    selection=deepcopy(State.selection1),
    cursor=deepcopy(State.cursor1),
    current_drawing_mode=Drawing_mode,
    previous_drawing_mode=State.previous_drawing_mode,
    lines={},
    start_line=s,
    end_line=e,
    -- no filename; undo history is cleared when filename changes
  }
  -- deep copy lines without cached stuff like text fragments
  for i=s,e do
    local line = State.lines[i]
    if line.mode == 'text' then
      table.insert(event.lines, {mode='text', data=line.data})
    elseif line.mode == 'drawing' then
      local points=deepcopy(line.points)
--?       print('copying', line.points, 'with', #line.points, 'points into', points)
      local shapes=deepcopy(line.shapes)
--?       print('copying', line.shapes, 'with', #line.shapes, 'shapes into', shapes)
      table.insert(event.lines, {mode='drawing', h=line.h, points=points, shapes=shapes, pending={}})
--?       table.insert(event.lines, {mode='drawing', h=line.h, points=deepcopy(line.points), shapes=deepcopy(line.shapes), pending={}})
    else
      print(line.mode)
      assert(false)
    end
  end
  return event
end

function patch(lines, from, to)
--?   if #from.lines == 1 and #to.lines == 1 then
--?     assert(from.start_line == from.end_line)
--?     assert(to.start_line == to.end_line)
--?     assert(from.start_line == to.start_line)
--?     lines[from.start_line] = to.lines[1]
--?     return
--?   end
  assert(from.start_line == to.start_line)
  for i=from.end_line,from.start_line,-1 do
    table.remove(lines, i)
  end
  assert(#to.lines == to.end_line-to.start_line+1)
  for i=1,#to.lines do
    table.insert(lines, to.start_line+i-1, to.lines[i])
  end
end

function patch_placeholders(line_cache, from, to)
  assert(from.start_line == to.start_line)
  for i=from.end_line,from.start_line,-1 do
    table.remove(line_cache, i)
  end
  assert(#to.lines == to.end_line-to.start_line+1)
  for i=1,#to.lines do
    table.insert(line_cache, to.start_line+i-1, {})
  end
end

-- https://stackoverflow.com/questions/640642/how-do-you-copy-a-lua-table-by-value/26367080#26367080
function deepcopy(obj, seen)
  if type(obj) ~= 'table' then return obj end
  if seen and seen[obj] then return seen[obj] end
  local s = seen or {}
  local result = setmetatable({}, getmetatable(obj))
  s[obj] = result
  for k,v in pairs(obj) do
    result[deepcopy(k, s)] = deepcopy(v, s)
  end
  return result
end

function minmax(a, b)
  return math.min(a,b), math.max(a,b)
end