Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Port test-fs-readfile-unlink from node.js

  • Loading branch information...
commit f74ac593565bb54ec446599a6565bd5571012d3f 1 parent 28bb39f
@hnakamur hnakamur authored
Showing with 47 additions and 0 deletions.
  1. +47 −0 tests/test-fs-readfile-unlink.lua
View
47 tests/test-fs-readfile-unlink.lua
@@ -0,0 +1,47 @@
+--[[
+
+Copyright 2012 The Luvit Authors. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License")
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS-IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+--]]
+
+require("helper")
+
+local FS = require('fs')
+local Path = require('path')
+local Buffer = require('buffer').Buffer
+local string = require('string')
+
+local dirName = Path.join(__dirname, 'fixtures', 'test-readfile-unlink')
+local fileName = Path.join(dirName, 'test.bin')
+
+local bufStr = string.rep(string.char(42), 512 * 1024)
+local buf = Buffer:new(bufStr)
+
+local ok, err
+ok, err = pcall(FS.mkdirSync, dirName, '0777')
+if not ok then
+ assert(err.code == 'EEXIST')
+end
+
+FS.writeFileSync(fileName, buf:toString())
+
+FS.readFile(fileName, function(err, data)
+ assert(err == nil)
+ assert(#data == buf.length)
+ assert(string.byte(data, 1) == 42)
+
+ FS.unlinkSync(fileName)
+ FS.rmdirSync(dirName)
+end)
Please sign in to comment.
Something went wrong with that request. Please try again.