Before

1--- Basic async test functions.
2--
3-- @copyright 2017 Aidan Holm <aidanholm@gmail.com>
4
5local T = {}
6local test = require "tests.lib"
7local assert = require("luassert")
8local spy = require 'luassert.spy'
9local match = require("luassert.match")
10
11uris = {"about:blank"}
12require "config.rc"
13
14local window = require "window"
15local w = assert(select(2, next(window.bywidget)))
16
17T.test_undo_close_works = function ()
18 -- Load page in new tab
19 local uri = test.http_server() .. "undoclose_page.html"
20 w:new_tab(uri)
21 assert(w.tabs:current() == 2)
22 test.wait_for_view(w.view)
23
24 -- Try to open the menu
25 local notify_spy = spy.on(window.methods, "notify")
26 w:run_cmd(":undolist")
27 assert.spy(notify_spy).was.called_with(match._, "No closed tabs to display")
28 assert(w:is_mode("normal"))
29
30 -- Close the tab
31 w:close_tab()
32 assert(w.tabs:current() == 1)
33
34 -- Try to open the menu again
35 notify_spy = spy.on(window.methods, "notify")
36 w:run_cmd(":undolist")
37 assert.spy(notify_spy).was_not_called_with(match._, "No closed tabs to display")
38 assert(w:is_mode("undolist"))
39 w:set_mode("normal")
40
41 -- Undo-close the tab
42 w:undo_close_tab(1)
43 assert(w.tabs:current() == 2)
44 test.wait_for_view(w.view)
45 test.wait_for_signal(w.view, "property::title", 2000)
46
47 assert(w.view.uri == uri)
48 assert(w.view.title == "undoclose_page")
49
50 -- Restore to initial state
51 w:close_tab()
52 assert(w.tabs:current() == 1)
53 assert(w.view.uri == "about:blank")
54end
55
56T.test_undo_close_restores_tab_history = function ()
57 -- Load page in new tab
58 local uri = test.http_server() .. "undoclose_page.html"
59 w:new_tab(uri)
60 assert.is_equal(w.tabs:current(), 2)
61 test.wait_for_view(w.view)
62
63 -- Navigate to about:blank
64 w.view.uri = "about:blank"
65 test.wait_for_view(w.view)
66
67 -- Close and undo-close
68 w:close_tab()
69 w:undo_close_tab()
70 test.wait_for_view(w.view)
71 assert.is_equal(w.tabs:current(), 2)
72 assert.is_equal(w.view.uri, 'about:blank')
73
74 -- Navigate back
75 w:back(1)
…lines 76–88 unchanged (13 lines)

After

1--- Basic async test functions.
2--
3-- @copyright 2017 Aidan Holm <aidanholm@gmail.com>
4
5local T = {}
6local test = require("tests.lib")
7local assert = require("luassert")
8local spy = require("luassert.spy")
9local match = require("luassert.match")
10
11uris = {"about:blank"}
12require "config.rc"
13
14local window = require "window"
15local w = assert(select(2, next(window.bywidget)))
16
17T.test_undo_close_restores_tab_history = function ()
18 -- Load page in new tab
19 local uri = test.http_server() .. "undoclose_page.html"
20 w:new_tab(uri)
21 assert.is_equal(w.tabs:current(), 2)
22 test.wait_for_view(w.view)
23
24 -- Try to open the menu
25 local notify_spy = spy.on(window.methods, "notify")
26 w:run_cmd(":undolist")
27 assert.spy(notify_spy).was.called_with(match._, "No closed tabs to display")
28 assert(w:is_mode("normal"))
29
30 -- Navigate to about:blank
31 w.view.uri = "about:blank"
32 test.wait_for_view(w.view)
33
34 -- Close
35 w:close_tab()
36
37 -- Try to open the menu again
38 notify_spy = spy.on(window.methods, "notify")
39 w:run_cmd(":undolist")
40 assert.spy(notify_spy).was_not_called_with(match._, "No closed tabs to display")
41 assert(w:is_mode("undolist"))
42 w:set_mode("normal")
43
44 -- Undo Close
45 w:undo_close_tab()
46 test.wait_for_view(w.view)
47 assert.is_equal(w.tabs:current(), 2)
48 assert.is_equal(w.view.uri, 'about:blank')
49
50 -- Close again
51 w:close_tab()
52
53 -- Undo Close again with argument
54 w:undo_close_tab(1)
55 test.wait_for_view(w.view)
56 assert.is_equal(w.tabs:current(), 2)
57 assert.is_equal(w.view.uri, 'about:blank')
58
59 -- Navigate back
60 w:back(1)
…lines 61–73 unchanged (13 lines)

Before

chunk
comment
-- "--"
comment_content "- Basic async test functions."
comment
-- "--"
comment_content ""
comment
-- "--"
comment_content " @copyright 2017 Aidan Holm <aidanholm@gmail.com>"
variable_declaration
local "local"
assignment_statement
variable_list
identifier "T"
= "="
expression_list
table_constructor
{ "{"
} "}"
variable_declaration
local "local"
assignment_statement
variable_list
identifier "test"
= "="
expression_list
function_call
identifier "require"
arguments
string
" "\""
string_content "tests.lib"
" "\""
variable_declaration
local "local"
assignment_statement
variable_list
identifier "assert"
= "="
expression_list
function_call
identifier "require"
arguments
( "("
string
" "\""
string_content "luassert"
" "\""
) ")"
variable_declaration
local "local"
assignment_statement
variable_list
identifier "spy"
= "="
expression_list
function_call
identifier "require"
arguments
string
' "'"
string_content "luassert.spy"
' "'"
variable_declaration
local "local"
assignment_statement
variable_list
identifier "match"
= "="
expression_list
function_call
identifier "require"
arguments
( "("
string
" "\""
string_content "luassert.match"
" "\""
) ")"
assignment_statement
variable_list
identifier "uris"
= "="
expression_list
table_constructor
{ "{"
field
string
" "\""
string_content "about:blank"
" "\""
} "}"
function_call
identifier "require"
arguments
string
" "\""
string_content "config.rc"
" "\""
variable_declaration
local "local"
assignment_statement
variable_list
identifier "window"
= "="
expression_list
function_call
identifier "require"
arguments
string
" "\""
string_content "window"
" "\""
variable_declaration (+28 nodes collapsed)
assignment_statement
variable_list
dot_index_expression
identifier "T"
. "."
identifier "test_undo_close_works"
= "="
expression_list
function_definition
function "function"
parameters
( "("
) ")"
comment
-- "--"
comment_content " Load page in new tab"
block
variable_declaration (+21 nodes collapsed)
function_call
method_index_expression
identifier "w"
: ":"
identifier "new_tab"
arguments
( "("
identifier "uri"
) ")"
function_call
identifier "assert"
arguments
( "("
binary_expression
function_call
method_index_expression
dot_index_expression
identifier "w"
. "."
identifier "tabs"
: ":"
identifier "current"
arguments
( "("
) ")"
== "=="
number "2"
) ")"
function_call
dot_index_expression
identifier "test"
. "."
identifier "wait_for_view"
arguments
( "("
dot_index_expression
identifier "w"
. "."
identifier "view"
) ")"
comment
-- "--"
comment_content " Try to open the menu"
variable_declaration (+24 nodes collapsed)
function_call
method_index_expression
identifier "w"
: ":"
identifier "run_cmd"
arguments
( "("
string
" "\""
string_content ":undolist"
" "\""
) ")"
function_call (+28 nodes collapsed)
function_call
identifier "assert"
arguments
( "("
function_call
method_index_expression
identifier "w"
: ":"
identifier "is_mode"
arguments
( "("
string
" "\""
string_content "normal"
" "\""
) ")"
) ")"
comment
-- "--"
comment_content " Close the tab"
function_call
method_index_expression
identifier "w"
: ":"
identifier "close_tab"
arguments
( "("
) ")"
function_call
identifier "assert"
arguments
( "("
binary_expression
function_call
method_index_expression
dot_index_expression
identifier "w"
. "."
identifier "tabs"
: ":"
identifier "current"
arguments
( "("
) ")"
== "=="
number "1"
) ")"
comment
-- "--"
comment_content " Try to open the menu again"
assignment_statement (+22 nodes collapsed)
function_call
method_index_expression
identifier "w"
: ":"
identifier "run_cmd"
arguments
( "("
string
" "\""
string_content ":undolist"
" "\""
) ")"
function_call (+25 nodes collapsed)
function_call
identifier "assert"
arguments
( "("
function_call
method_index_expression
identifier "w"
: ":"
identifier "is_mode"
arguments
( "("
string
" "\""
string_content "undolist"
" "\""
) ")"
) ")"
function_call
method_index_expression
identifier "w"
: ":"
identifier "set_mode"
arguments
( "("
string
" "\""
string_content "normal"
" "\""
) ")"
comment
-- "--"
comment_content " Undo-close the tab"
function_call
method_index_expression
identifier "w"
: ":"
identifier "undo_close_tab"
arguments
( "("
number "1"
) ")"
function_call
identifier "assert"
arguments
( "("
binary_expression
function_call
method_index_expression
dot_index_expression
identifier "w"
. "."
identifier "tabs"
: ":"
identifier "current"
arguments
( "("
) ")"
== "=="
number "2"
) ")"
function_call
dot_index_expression
identifier "test"
. "."
identifier "wait_for_view"
arguments
( "("
dot_index_expression
identifier "w"
. "."
identifier "view"
) ")"
function_call
dot_index_expression
identifier "test"
. "."
identifier "wait_for_signal"
arguments
( "("
dot_index_expression
identifier "w"
. "."
identifier "view"
, ","
string
" "\""
string_content "property::title"
" "\""
, ","
number "2000"
) ")"
function_call
identifier "assert"
arguments
( "("
binary_expression
dot_index_expression
dot_index_expression
identifier "w"
. "."
identifier "view"
. "."
identifier "uri"
== "=="
identifier "uri"
) ")"
function_call
identifier "assert"
arguments
( "("
binary_expression
dot_index_expression
dot_index_expression
identifier "w"
. "."
identifier "view"
. "."
identifier "title"
== "=="
string
" "\""
string_content "undoclose_page"
" "\""
) ")"
comment
-- "--"
comment_content " Restore to initial state"
function_call
method_index_expression
identifier "w"
: ":"
identifier "close_tab"
arguments
( "("
) ")"
function_call
identifier "assert"
arguments
( "("
binary_expression
function_call
method_index_expression
dot_index_expression
identifier "w"
. "."
identifier "tabs"
: ":"
identifier "current"
arguments
( "("
) ")"
== "=="
number "1"
) ")"
function_call
identifier "assert"
arguments
( "("
binary_expression
dot_index_expression
dot_index_expression
identifier "w"
. "."
identifier "view"
. "."
identifier "uri"
== "=="
string
" "\""
string_content "about:blank"
" "\""
) ")"
end "end"
assignment_statement
variable_list
dot_index_expression
identifier "T"
. "."
identifier "test_undo_close_restores_tab_history"
= "="
expression_list
function_definition
function "function"
parameters
( "("
) ")"
comment
-- "--"
comment_content " Load page in new tab"
block
variable_declaration
local "local"
assignment_statement
variable_list
identifier "uri"
= "="
expression_list
binary_expression
function_call
dot_index_expression
identifier "test"
. "."
identifier "http_server"
arguments
( "("
) ")"
.. ".."
string
" "\""
string_content "undoclose_page.html"
" "\""
function_call
method_index_expression
identifier "w"
: ":"
identifier "new_tab"
arguments
( "("
identifier "uri"
) ")"
function_call (+21 nodes collapsed)
function_call
dot_index_expression
identifier "test"
. "."
identifier "wait_for_view"
arguments
( "("
dot_index_expression
identifier "w"
. "."
identifier "view"
) ")"
comment
-- "--"
comment_content " Navigate to about:blank"
assignment_statement
variable_list
dot_index_expression
dot_index_expression
identifier "w"
. "."
identifier "view"
. "."
identifier "uri"
= "="
expression_list
string
" "\""
string_content "about:blank"
" "\""
function_call
dot_index_expression
identifier "test"
. "."
identifier "wait_for_view"
arguments
( "("
dot_index_expression
identifier "w"
. "."
identifier "view"
) ")"
comment
-- "--"
comment_content " Close and undo-close"
function_call
method_index_expression
identifier "w"
: ":"
identifier "close_tab"
arguments
( "("
) ")"
function_call
method_index_expression
identifier "w"
: ":"
identifier "undo_close_tab"
arguments
( "("
) ")"
function_call
dot_index_expression
identifier "test"
. "."
identifier "wait_for_view"
arguments
( "("
dot_index_expression
identifier "w"
. "."
identifier "view"
) ")"
function_call (+21 nodes collapsed)
function_call
dot_index_expression
identifier "assert"
. "."
identifier "is_equal"
arguments
( "("
dot_index_expression
dot_index_expression
identifier "w"
. "."
identifier "view"
. "."
identifier "uri"
, ","
string
' "'"
string_content "about:blank"
' "'"
) ")"
comment
-- "--"
comment_content " Navigate back"
function_call
method_index_expression
identifier "w"
: ":"
identifier "back"
arguments
( "("
number "1"
) ")"
function_call
dot_index_expression
identifier "test"
. "."
identifier "wait_for_view"
arguments
( "("
dot_index_expression
identifier "w"
. "."
identifier "view"
) ")"
function_call
dot_index_expression
identifier "assert"
. "."
identifier "is_equal"
arguments
( "("
dot_index_expression
dot_index_expression
identifier "w"
. "."
identifier "view"
. "."
identifier "uri"
, ","
identifier "uri"
) ")"
comment
-- "--"
comment_content " Restore to initial state"
function_call
method_index_expression
identifier "w"
: ":"
identifier "close_tab"
arguments
( "("
) ")"
function_call
identifier "assert"
arguments
( "("
binary_expression
function_call
method_index_expression
dot_index_expression
identifier "w"
. "."
identifier "tabs"
: ":"
identifier "current"
arguments
( "("
) ")"
== "=="
number "1"
) ")"
function_call
identifier "assert"
arguments
( "("
binary_expression
dot_index_expression
dot_index_expression
identifier "w"
. "."
identifier "view"
. "."
identifier "uri"
== "=="
string
" "\""
string_content "about:blank"
" "\""
) ")"
end "end"
return_statement
return "return"
expression_list
identifier "T"
comment
-- "--"
comment_content " vim: et:sw=4:ts=8:sts=4:tw=80"

After

chunk
comment
-- "--"
comment_content "- Basic async test functions."
comment
-- "--"
comment_content ""
comment
-- "--"
comment_content " @copyright 2017 Aidan Holm <aidanholm@gmail.com>"
variable_declaration
local "local"
assignment_statement
variable_list
identifier "T"
= "="
expression_list
table_constructor
{ "{"
} "}"
variable_declaration
local "local"
assignment_statement
variable_list
identifier "test"
= "="
expression_list
function_call
identifier "require"
arguments
( "("
string
" "\""
string_content "tests.lib"
" "\""
) ")"
variable_declaration
local "local"
assignment_statement
variable_list
identifier "assert"
= "="
expression_list
function_call
identifier "require"
arguments
( "("
string
" "\""
string_content "luassert"
" "\""
) ")"
variable_declaration
local "local"
assignment_statement
variable_list
identifier "spy"
= "="
expression_list
function_call
identifier "require"
arguments
( "("
string
" "\""
string_content "luassert.spy"
" "\""
) ")"
variable_declaration
local "local"
assignment_statement
variable_list
identifier "match"
= "="
expression_list
function_call
identifier "require"
arguments
( "("
string
" "\""
string_content "luassert.match"
" "\""
) ")"
assignment_statement
variable_list
identifier "uris"
= "="
expression_list
table_constructor
{ "{"
field
string
" "\""
string_content "about:blank"
" "\""
} "}"
function_call
identifier "require"
arguments
string
" "\""
string_content "config.rc"
" "\""
variable_declaration
local "local"
assignment_statement
variable_list
identifier "window"
= "="
expression_list
function_call
identifier "require"
arguments
string
" "\""
string_content "window"
" "\""
variable_declaration (+28 nodes collapsed)
assignment_statement
variable_list
dot_index_expression
identifier "T"
. "."
identifier "test_undo_close_restores_tab_history"
= "="
expression_list
function_definition
function "function"
parameters
( "("
) ")"
comment
-- "--"
comment_content " Load page in new tab"
block
variable_declaration (+21 nodes collapsed)
function_call
method_index_expression
identifier "w"
: ":"
identifier "new_tab"
arguments
( "("
identifier "uri"
) ")"
function_call
dot_index_expression
identifier "assert"
. "."
identifier "is_equal"
arguments
( "("
function_call
method_index_expression
dot_index_expression
identifier "w"
. "."
identifier "tabs"
: ":"
identifier "current"
arguments
( "("
) ")"
, ","
number "2"
) ")"
function_call
dot_index_expression
identifier "test"
. "."
identifier "wait_for_view"
arguments
( "("
dot_index_expression
identifier "w"
. "."
identifier "view"
) ")"
comment
-- "--"
comment_content " Try to open the menu"
variable_declaration (+24 nodes collapsed)
function_call
method_index_expression
identifier "w"
: ":"
identifier "run_cmd"
arguments
( "("
string
" "\""
string_content ":undolist"
" "\""
) ")"
function_call (+28 nodes collapsed)
function_call
identifier "assert"
arguments
( "("
function_call
method_index_expression
identifier "w"
: ":"
identifier "is_mode"
arguments
( "("
string
" "\""
string_content "normal"
" "\""
) ")"
) ")"
comment
-- "--"
comment_content " Navigate to about:blank"
assignment_statement
variable_list
dot_index_expression
dot_index_expression
identifier "w"
. "."
identifier "view"
. "."
identifier "uri"
= "="
expression_list
string
" "\""
string_content "about:blank"
" "\""
function_call
dot_index_expression
identifier "test"
. "."
identifier "wait_for_view"
arguments
( "("
dot_index_expression
identifier "w"
. "."
identifier "view"
) ")"
comment
-- "--"
comment_content " Close"
function_call
method_index_expression
identifier "w"
: ":"
identifier "close_tab"
arguments
( "("
) ")"
comment
-- "--"
comment_content " Try to open the menu again"
assignment_statement (+22 nodes collapsed)
function_call
method_index_expression
identifier "w"
: ":"
identifier "run_cmd"
arguments
( "("
string
" "\""
string_content ":undolist"
" "\""
) ")"
function_call (+25 nodes collapsed)
function_call
identifier "assert"
arguments
( "("
function_call
method_index_expression
identifier "w"
: ":"
identifier "is_mode"
arguments
( "("
string
" "\""
string_content "undolist"
" "\""
) ")"
) ")"
function_call
method_index_expression
identifier "w"
: ":"
identifier "set_mode"
arguments
( "("
string
" "\""
string_content "normal"
" "\""
) ")"
comment
-- "--"
comment_content " Undo Close"
function_call
method_index_expression
identifier "w"
: ":"
identifier "undo_close_tab"
arguments
( "("
) ")"
function_call
dot_index_expression
identifier "test"
. "."
identifier "wait_for_view"
arguments
( "("
dot_index_expression
identifier "w"
. "."
identifier "view"
) ")"
function_call (+21 nodes collapsed)
function_call
dot_index_expression
identifier "assert"
. "."
identifier "is_equal"
arguments
( "("
dot_index_expression
dot_index_expression
identifier "w"
. "."
identifier "view"
. "."
identifier "uri"
, ","
string
' "'"
string_content "about:blank"
' "'"
) ")"
comment
-- "--"
comment_content " Close again"
function_call
method_index_expression
identifier "w"
: ":"
identifier "close_tab"
arguments
( "("
) ")"
comment
-- "--"
comment_content " Undo Close again with argument"
function_call
method_index_expression
identifier "w"
: ":"
identifier "undo_close_tab"
arguments
( "("
number "1"
) ")"
function_call
dot_index_expression
identifier "test"
. "."
identifier "wait_for_view"
arguments
( "("
dot_index_expression
identifier "w"
. "."
identifier "view"
) ")"
function_call (+21 nodes collapsed)
function_call
dot_index_expression
identifier "assert"
. "."
identifier "is_equal"
arguments
( "("
dot_index_expression
dot_index_expression
identifier "w"
. "."
identifier "view"
. "."
identifier "uri"
, ","
string
' "'"
string_content "about:blank"
' "'"
) ")"
comment
-- "--"
comment_content " Navigate back"
function_call
method_index_expression
identifier "w"
: ":"
identifier "back"
arguments
( "("
number "1"
) ")"
function_call
dot_index_expression
identifier "test"
. "."
identifier "wait_for_view"
arguments
( "("
dot_index_expression
identifier "w"
. "."
identifier "view"
) ")"
function_call
dot_index_expression
identifier "assert"
. "."
identifier "is_equal"
arguments
( "("
dot_index_expression
dot_index_expression
identifier "w"
. "."
identifier "view"
. "."
identifier "uri"
, ","
identifier "uri"
) ")"
comment
-- "--"
comment_content " Restore to initial state"
function_call
method_index_expression
identifier "w"
: ":"
identifier "close_tab"
arguments
( "("
) ")"
function_call
identifier "assert"
arguments
( "("
binary_expression
function_call
method_index_expression
dot_index_expression
identifier "w"
. "."
identifier "tabs"
: ":"
identifier "current"
arguments
( "("
) ")"
== "=="
number "1"
) ")"
function_call
identifier "assert"
arguments
( "("
binary_expression
dot_index_expression
dot_index_expression
identifier "w"
. "."
identifier "view"
. "."
identifier "uri"
== "=="
string
" "\""
string_content "about:blank"
" "\""
) ")"
end "end"
return_statement
return "return"
expression_list
identifier "T"
comment
-- "--"
comment_content " vim: et:sw=4:ts=8:sts=4:tw=80"