Permalink
Browse files

Use good-style if-statements (avoid one-line if-statements).

  • Loading branch information...
1 parent 7e3678a commit bd6ec21e9f344452e91c038fe2f417047800dd74 @hnakamur hnakamur committed Aug 21, 2012
@@ -41,13 +41,17 @@ local ncallbacks = 0
-- test that empty file will be created and have content added
FS.appendFile(filename, s, function(e)
- if e then return e end
+ if e then
+ return e
+ end
ncallbacks = ncallbacks + 1
p('appended to file')
FS.readFile(filename, function(e, buffer)
- if e then return e end
+ if e then
+ return e
+ end
p('file read')
ncallbacks = ncallbacks + 1
assert(#buffer == #s)
@@ -59,13 +63,17 @@ local filename2 = join(__dirname, 'fixtures', 'append2.txt')
FS.writeFileSync(filename2, currentFileData)
FS.appendFile(filename2, s, function(e)
- if e then return e end
+ if e then
+ return e
+ end
ncallbacks = ncallbacks + 1
p('appended to file2')
FS.readFile(filename2, function(e, buffer)
- if e then return e end
+ if e then
+ return e
+ end
p('file2 read')
ncallbacks = ncallbacks + 1
assert(#buffer == #s + #currentFileData)
@@ -80,13 +88,17 @@ local buf = Buffer:new(s)
p('appending to ' .. filename3)
FS.appendFile(filename3, buf:toString(), function(e)
- if e then return e end
+ if e then
+ return e
+ end
ncallbacks = ncallbacks + 1
p('appended to file3')
FS.readFile(filename3, function(e, buffer)
- if e then return e end
+ if e then
+ return e
+ end
p('file3 read')
ncallbacks = ncallbacks + 1
assert(#buffer == buf.length + #currentFileData)
@@ -100,13 +112,17 @@ FS.writeFileSync(filename4, currentFileData)
p('appending to ' .. filename4)
FS.appendFile(filename4, tostring(n), function(e)
- if e then return e end
+ if e then
+ return e
+ end
ncallbacks = ncallbacks + 1
p('appended to file4')
FS.readFile(filename4, function(e, buffer)
- if e then return e end
+ if e then
+ return e
+ end
p('file4 read')
ncallbacks = ncallbacks + 1
assert(#buffer == #tostring(n) + #currentFileData)
View
@@ -29,7 +29,9 @@ p('open ' .. file)
FS.open(file, 'a', '0777', function(err, fd)
p('fd ' .. fd)
- if err then return err end
+ if err then
+ return err
+ end
FS.fdatasyncSync(fd)
p('fdatasync SYNC: ok')
@@ -40,11 +42,15 @@ FS.open(file, 'a', '0777', function(err, fd)
successes = successes + 1
FS.fdatasync(fd, function(err)
- if err then return err end
+ if err then
+ return err
+ end
p('fdatasync ASYNC: ok')
successes = successes + 1
FS.fsync(fd, function(err)
- if err then return err end
+ if err then
+ return err
+ end
p('fsync ASYNC: ok')
successes = successes + 1
end)
@@ -35,11 +35,15 @@ p('fileName=' .. fileName)
p('fileNameLength=' .. #fileName)
FS.writeFile(fileName, 'ok', function(err)
- if err then return err end
+ if err then
+ return err
+ end
successes = successes + 1
FS.stat(fileName, function(err, stats)
- if err then return err end
+ if err then
+ return err
+ end
successes = successes + 1
end)
end)
View
@@ -30,15 +30,19 @@ assert(err.source == 'open')
local openFd
FS.open(__filename, 'r', function(err, fd)
- if err then return err end
+ if err then
+ return err
+ end
openFd = fd
end)
-- TODO: Support file open flag 's'
--[[
local openFd2
FS.open(__filename, 'rs', function(err, fd)
- if err then return err end
+ if err then
+ return err
+ end
openFd2 = fd
end)
--]]
@@ -31,7 +31,9 @@ FS._fstatSync = FS.fstatSync
FS.fstat = function(fd, cb)
FS._fstat(fd, function(er, st)
- if er then return cb(er) end
+ if er then
+ return cb(er)
+ end
st.size = 0
return cb(er, st)
end)
View
@@ -60,21 +60,33 @@ FS.closeSync(fd)
function testTruncate(cb)
FS.writeFile(filename, data, function(er)
- if er then return cb(er) end
+ if er then
+ return cb(er)
+ end
FS.stat(filename, function(er, stat)
- if er then return cb(er) end
+ if er then
+ return cb(er)
+ end
assert(stat.size == 1024 * 16)
FS.truncate(filename, 1024, function(er)
- if er then return cb(er) end
+ if er then
+ return cb(er)
+ end
FS.stat(filename, function(er, stat)
- if er then return cb(er) end
+ if er then
+ return cb(er)
+ end
assert(stat.size == 1024)
FS.truncate(filename, function(er)
- if er then return cb(er) end
+ if er then
+ return cb(er)
+ end
FS.stat(filename, function(er, stat)
- if er then return cb(er) end
+ if er then
+ return cb(er)
+ end
assert(stat.size == 0)
cb()
end)
@@ -88,23 +100,37 @@ end
function testFtruncate(cb)
FS.writeFile(filename, data, function(er)
- if er then return cb(er) end
+ if er then
+ return cb(er)
+ end
FS.stat(filename, function(er, stat)
- if er then return cb(er) end
+ if er then
+ return cb(er)
+ end
assert(stat.size == 1024 * 16)
FS.open(filename, 'w', function(er, fd)
- if er then return cb(er) end
+ if er then
+ return cb(er)
+ end
FS.ftruncate(fd, 1024, function(er)
- if er then return cb(er) end
+ if er then
+ return cb(er)
+ end
FS.stat(filename, function(er, stat)
- if er then return cb(er) end
+ if er then
+ return cb(er)
+ end
assert(stat.size == 1024)
FS.ftruncate(fd, function(er)
- if er then return cb(er) end
+ if er then
+ return cb(er)
+ end
FS.stat(filename, function(er, stat)
- if er then return cb(er) end
+ if er then
+ return cb(er)
+ end
assert(stat.size == 0)
FS.close(fd, cb)
end)
@@ -119,10 +145,14 @@ end
-- async tests
local success = 0
testTruncate(function(er)
- if er then return er end
+ if er then
+ return er
+ end
success = success + 1
testFtruncate(function(er)
- if er then return er end
+ if er then
+ return er
+ end
success = success + 1
end)
end)
@@ -37,13 +37,17 @@ local s = '南越国是前203年至前111年存在于岭南地区的一个国家
local ncallbacks = 0
FS.writeFile(filename, s, function(err)
- if err then return err end
+ if err then
+ return err
+ end
ncallbacks = ncallbacks + 1
p('file written')
FS.readFile(filename, function(err, buffer)
- if err then return err end
+ if err then
+ return err
+ end
p('file read')
ncallbacks = ncallbacks + 1
assert(#s == #buffer)
@@ -60,13 +64,17 @@ local buf = Buffer:new(s)
p('writing to ' .. filename2)
FS.writeFile(filename, buf, function(err)
- if err then return err end
+ if err then
+ return err
+ end
ncallbacks = ncallbacks + 1
p('file2 written')
FS.readFile(filename2, function(err, buffer)
- if err then return err end
+ if err then
+ return err
+ end
p('file2 read')
ncallbacks = ncallbacks + 1
assert(#buf == #buffer)
@@ -82,13 +90,17 @@ local filename3 = Path.join(__dirname, 'fixtures', 'test3.txt')
p('writing to ' .. filename3)
FS.writeFile(filename, n, function(err)
- if err then return err end
+ if err then
+ return err
+ end
ncallbacks = ncallbacks + 1
p('file3 written')
FS.readFile(filename3, function(err, buffer)
- if err then return err end
+ if err then
+ return err
+ end
p('file3 read')
ncallbacks = ncallbacks + 1
assert(#tostring(n) == #buffer)
View
@@ -29,15 +29,19 @@ local expected = 'ümlaut.'
local found, found2
FS.open(fn, 'w', tonumber('0644', 8), function(err, fd)
- if err then return err end
+ if err then
+ return err
+ end
p('open done')
-- TODO: support same arguments as fs.write in node.js
FS.write(fd, 0, '', function(err, written)
assert(0 == written)
end)
FS.write(fd, 0, expected, function(err, written)
p('write done')
- if err then return err end
+ if err then
+ return err
+ end
assert(#expected == written)
FS.closeSync(fd)
found = FS.readFileSync(fn)
@@ -50,14 +54,18 @@ end)
FS.open(fn2, 'w', tonumber('0644', 8),
function(err, fd)
- if err then return err end
+ if err then
+ return err
+ end
p('open done')
FS.write(fd, 0, '', function(err, written)
assert(0 == written)
end)
FS.write(fd, 0, expected, function(err, written)
p('write done')
- if err then return err end
+ if err then
+ return err
+ end
assert(#expected == written)
FS.closeSync(fd)
found2 = FS.readFileSync(fn2)

0 comments on commit bd6ec21

Please sign in to comment.