Warning: file_get_contents(http://localhost:8000/calc?cmd=524&userid=0&debug=1): failed to open stream: Cannot assign requested address in /var/www/tb/show-snippet.php on line 158
Find snippet references in a text [524]

Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

27
LINES

< > BotCompany Repo | #524 // Find snippet references in a text

Lua code - System test

1  
get("#349") -- table functions
2  
3  
-- an example text (taken from #523)
4  
5  
text = [[
6  
get("#515") -- splitLines
7  
text = getSnippet("#2000025")
8  
lines = splitLines(text)
9  
header = lines[1]:gsub(" +", " "):gsub("^ ", ""):gsub(" $", "")
10  
print(header)
11  
]]
12  
13  
function findReferences(text)
14  
  refs = {}
15  
  for word in text:gmatch("#%d+") do
16  
    refs[word] = true
17  
  end
18  
  return keystolist(refs)
19  
end
20  
21  
refs = findReferences(text)
22  
table.sort(refs)
23  
s = table.concat(refs, " ")
24  
print(s)
25  
assert(s == "#2000025 #515")
26  
27  
return true

test run  test run with input  download  show line numbers   

Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

Comments [hide]

ID Author/Program Comment Date
685 #1000610 Edit suggestion:
!636
!629

main {
static Object androidContext;
static String programID;

public static void main(String[] args) throws Exception {
get("#349") -- table functions

-- an example text (taken from #523)

text = [[
get("#515") -- splitLines
text = getSnippet("#2000025")
lines = splitLines(text)
header = lines[1]:gsub(" +", " "):gsub("^ ", ""):gsub(" $", "")
print(header)
]]

function findReferences(text)
refs = {}
for word in text:gmatch("#%d+") do
refs[word] = true
end
return keystolist(refs)
end

refs = findReferences(text)
table.sort(refs)
s = table.concat(refs, " ")
print(s)
assert(s == "#2000025 #515")

return true
}}
2015-08-19 08:28:29  delete 
683 #1000604 (pitcher) 2015-08-18 00:07:22

add comment

Snippet ID: #524
Snippet name: Find snippet references in a text
Eternal ID of this version: #524/1
Text MD5: 51bea7bb12e5ed575e36a3a9a17ccf71
Author: stefan
Category:
Type: Lua code - System test
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-03-12 17:47:12
Source code size: 530 bytes / 27 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 900 / 168
Referenced in: [show references]