mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-12-28 09:01:33 +03:00
Generate evil file fixtures depending on platform
This commit is contained in:
parent
6a37f9dad4
commit
4d415d3ca9
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,3 +8,4 @@ npm-debug.log
|
|||||||
/tags
|
/tags
|
||||||
/atom-shell/
|
/atom-shell/
|
||||||
docs/output
|
docs/output
|
||||||
|
spec/fixtures/evil-files/
|
||||||
|
@ -1 +0,0 @@
|
|||||||
I am evil because there's a UTF-8 character right here: ă
|
|
@ -3,10 +3,9 @@ fstream = require 'fstream'
|
|||||||
Project = require '../src/project'
|
Project = require '../src/project'
|
||||||
{_, fs} = require 'atom'
|
{_, fs} = require 'atom'
|
||||||
path = require 'path'
|
path = require 'path'
|
||||||
|
platform = require './spec-helper-platform'
|
||||||
BufferedProcess = require '../src/buffered-process'
|
BufferedProcess = require '../src/buffered-process'
|
||||||
|
|
||||||
isWindows = !!process.platform.match /^win/
|
|
||||||
|
|
||||||
describe "Project", ->
|
describe "Project", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
project.setPath(project.resolve('dir'))
|
project.setPath(project.resolve('dir'))
|
||||||
@ -387,63 +386,29 @@ describe "Project", ->
|
|||||||
range: [[2, 6], [2, 11]]
|
range: [[2, 6], [2, 11]]
|
||||||
|
|
||||||
it "works on evil filenames", ->
|
it "works on evil filenames", ->
|
||||||
temp = temp.mkdirSync("atom")
|
project.setPath(path.join(__dirname, 'fixtures', 'evil-files'))
|
||||||
target = path.join(temp, 'evil-files')
|
|
||||||
|
|
||||||
if fs.exists(target)
|
|
||||||
(fs.readdirSync(target) || []).forEach (f) ->
|
|
||||||
fs.unlinkSync(path.join(target, f))
|
|
||||||
fs.rmdirSync target
|
|
||||||
|
|
||||||
fs.mkdirSync(target)
|
|
||||||
|
|
||||||
inputs = []
|
|
||||||
if (isWindows)
|
|
||||||
inputs = [
|
|
||||||
"a_file_with_utf8.txt",
|
|
||||||
"file with spaces.txt",
|
|
||||||
"utfa\u0306.md"
|
|
||||||
]
|
|
||||||
else
|
|
||||||
inputs = [
|
|
||||||
"a_file_with_utf8.txt",
|
|
||||||
"file with spaces.txt",
|
|
||||||
"goddam\nnewlines",
|
|
||||||
"quote\".txt",
|
|
||||||
"utfa\u0306.md"
|
|
||||||
]
|
|
||||||
|
|
||||||
inputs.forEach (filename) ->
|
|
||||||
fd = fs.writeFileSync(path.join(target, filename), 'evil files!', { flag: 'w' })
|
|
||||||
console.log(target)
|
|
||||||
|
|
||||||
project.setPath temp
|
|
||||||
console.log("path: " + project.getPath())
|
|
||||||
|
|
||||||
paths = []
|
paths = []
|
||||||
matches = []
|
matches = []
|
||||||
waitsForPromise ->
|
waitsForPromise ->
|
||||||
project.scan /evil/, (result) ->
|
project.scan /evil/, (result) ->
|
||||||
paths.push(result.path)
|
paths.push(result.filePath)
|
||||||
matches.push(result.match)
|
matches = matches.concat(result.matches)
|
||||||
|
|
||||||
runs ->
|
runs ->
|
||||||
console.log(matches)
|
_.each(matches, (m) -> expect(m.matchText).toEqual 'evil')
|
||||||
console.log(paths)
|
|
||||||
try
|
|
||||||
expect(paths.length).toBe inputs.length
|
|
||||||
|
|
||||||
inputs.forEach (file) ->
|
if platform.isWindows()
|
||||||
itWorked = false
|
expect(paths.length).toBe 3
|
||||||
paths.forEach (p) ->
|
expect(paths[0]).toMatch /a_file_with_utf8.txt$/
|
||||||
itWorked = itWorked || p.endsWith(file)
|
expect(paths[1]).toMatch /file with spaces.txt$/
|
||||||
|
expect(path.basename(paths[2])).toBe "utfa\u0306.md"
|
||||||
expect(itWorked)
|
else
|
||||||
|
expect(paths.length).toBe 5
|
||||||
finally
|
expect(paths[0]).toMatch /a_file_with_utf8.txt$/
|
||||||
inputs.forEach (input) ->
|
expect(paths[1]).toMatch /file with spaces.txt$/
|
||||||
fs.unlinkSync (path.join(target, input))
|
expect(paths[2]).toMatch /goddam\nnewlines$/m
|
||||||
fs.rmdirSync target
|
expect(paths[3]).toMatch /quote".txt$/m
|
||||||
|
expect(path.basename(paths[4])).toBe "utfa\u0306.md"
|
||||||
|
|
||||||
it "ignores case if the regex includes the `i` flag", ->
|
it "ignores case if the regex includes the `i` flag", ->
|
||||||
results = []
|
results = []
|
||||||
|
38
spec/spec-helper-platform.coffee
Normal file
38
spec/spec-helper-platform.coffee
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
path = require 'path'
|
||||||
|
fsUtils = require '../src/fs-utils'
|
||||||
|
|
||||||
|
{_} = require 'atom'
|
||||||
|
|
||||||
|
## Platform specific helpers
|
||||||
|
module.exports =
|
||||||
|
# Public: Returns true if being run from within Windows
|
||||||
|
isWindows: ->
|
||||||
|
!!process.platform.match /^win/
|
||||||
|
|
||||||
|
# Public: Some files can not exist on Windows filesystems, so we have to
|
||||||
|
# selectively generate our fixtures.
|
||||||
|
#
|
||||||
|
# Returns nothing.
|
||||||
|
generateEvilFiles: ->
|
||||||
|
evilFilesPath = path.join(__dirname, 'fixtures', 'evil-files')
|
||||||
|
fsUtils.remove(evilFilesPath) if fsUtils.exists(evilFilesPath)
|
||||||
|
fsUtils.mkdirSync(evilFilesPath)
|
||||||
|
|
||||||
|
if (@isWindows())
|
||||||
|
filenames = [
|
||||||
|
"a_file_with_utf8.txt",
|
||||||
|
"file with spaces.txt",
|
||||||
|
"utfa\u0306.md"
|
||||||
|
]
|
||||||
|
else
|
||||||
|
filenames = [
|
||||||
|
"a_file_with_utf8.txt",
|
||||||
|
"file with spaces.txt",
|
||||||
|
"goddam\nnewlines",
|
||||||
|
"quote\".txt",
|
||||||
|
"utfa\u0306.md"
|
||||||
|
]
|
||||||
|
|
||||||
|
for filename in filenames
|
||||||
|
fd = fsUtils.writeFileSync(path.join(evilFilesPath, filename), 'evil file!', flag: 'w')
|
||||||
|
|
@ -12,8 +12,11 @@ Project = require '../src/project'
|
|||||||
Editor = require '../src/editor'
|
Editor = require '../src/editor'
|
||||||
TokenizedBuffer = require '../src/tokenized-buffer'
|
TokenizedBuffer = require '../src/tokenized-buffer'
|
||||||
pathwatcher = require 'pathwatcher'
|
pathwatcher = require 'pathwatcher'
|
||||||
|
platform = require './spec-helper-platform'
|
||||||
clipboard = require 'clipboard'
|
clipboard = require 'clipboard'
|
||||||
|
|
||||||
|
platform.generateEvilFiles()
|
||||||
|
|
||||||
atom.themes.loadBaseStylesheets()
|
atom.themes.loadBaseStylesheets()
|
||||||
atom.themes.requireStylesheet '../static/jasmine'
|
atom.themes.requireStylesheet '../static/jasmine'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user