UNPKG

4.36 kBtext/coffeescriptView Raw
1should = require "should"
2
3Parsers = require "../lib/parsers"
4
5describe "Parsers", ->
6 versionData = [
7 { channel: 'o', length: 40, body: 'Mercurial Distributed SCM (version 3.4)\n' },
8 { channel: 'o', length: 255, body: '(see http://mercurial.selenic.com for more information)\n\nCopyright (C) 2005-2015 Matt Mackall and others\nThis is free software; see the source for copying conditions. There is NO\nwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n' },
9 { channel: 'r', length: 4, body: 0 } ]
10
11 it "should extract version 3.4", (done) ->
12 version = Parsers.version versionData
13 version.should.equal "3.4"
14 done()
15
16 jsonData = [ { channel: 'o', length: 1, body: '[' },
17 { channel: 'o', length: 4, body: '\n {\n' },
18 { channel: 'o', length: 16, body: ' "active": true' },
19 { channel: 'o', length: 2, body: ',\n' },
20 { channel: 'o', length: 21, body: ' "branch": "default"' },
21 { channel: 'o', length: 2, body: ',\n' },
22 { channel: 'o', length: 17, body: ' "closed": false' },
23 { channel: 'o', length: 2, body: ',\n' },
24 { channel: 'o', length: 18, body: ' "current": false' },
25 { channel: 'o', length: 2, body: ',\n' },
26 { channel: 'o', length: 52, body: ' "node": "3358da28d762d898bfb01581fcb4384944312071"' },
27 { channel: 'o', length: 2, body: ',\n' },
28 { channel: 'o', length: 11, body: ' "rev": 44' },
29 { channel: 'o', length: 3, body: '\n }' },
30 { channel: 'o', length: 1, body: ',' },
31 { channel: 'o', length: 4, body: '\n {\n' },
32 { channel: 'o', length: 17, body: ' "active": false' },
33 { channel: 'o', length: 2, body: ',\n' },
34 { channel: 'o', length: 30, body: ' "branch": "branches-command"' },
35 { channel: 'o', length: 2, body: ',\n' },
36 { channel: 'o', length: 17, body: ' "closed": false' },
37 { channel: 'o', length: 2, body: ',\n' },
38 { channel: 'o', length: 18, body: ' "current": false' },
39 { channel: 'o', length: 2, body: ',\n' },
40 { channel: 'o', length: 52, body: ' "node": "7658b380389cb7da6b7c9d9574eb227d7045f070"' },
41 { channel: 'o', length: 2, body: ',\n' },
42 { channel: 'o', length: 11, body: ' "rev": 43' },
43 { channel: 'o', length: 3, body: '\n }' },
44 { channel: 'o', length: 3, body: '\n]\n' },
45 { channel: 'r', length: 4, body: 0 } ]
46
47 it "can parse json output", () ->
48 branches = Parsers.json jsonData
49 branches.should.have.length 2
50 branches[0].branch.should.be.equal "default"
51 branches[0].active.should.be.true
52 branches[1].branch.should.be.equal "branches-command"
53 branches[1].active.should.be.false
54
55 it "can parse raw text output", () ->
56 text = Parsers.text versionData
57 text.should.match /^Mercurial Distributed SCM[\s\S]*FITNESS FOR A PARTICULAR PURPOSE\.$/m
58
59 describe "Parsers given mercurial version 3.4 input", () ->
60 parsers = new Parsers "3.4"
61
62 tagsData = [
63 { channel: 'o', length: 3, body: 'tip' },
64 { channel: 'o', length: 46, body: ' 28:b1ce439e96b9' },
65 { channel: 'o', length: 1, body: '\n' },
66 { channel: 'o', length: 4, body: '1.11' },
67 { channel: 'o', length: 45, body: ' 27:00c9c34d6d00' },
68 { channel: 'o', length: 1, body: '\n' },
69 { channel: 'r', length: 4, body: 0 } ]
70
71 it "should extract tags", (done) ->
72 tags = parsers.tags tagsData
73 tags.should.have.property "1.11"
74 tags.should.have.property "tip"
75 tags.tip[0].should.equal "28"
76 tags.tip[1].should.equal "b1ce439e96b9"
77 done()
78
79 statusData = [
80 { channel: 'o', length: 2, body: 'A ' },
81 { channel: 'o', length: 19, body: 'lib/parsers.coffee\n' },
82 { channel: 'o', length: 2, body: 'C ' },
83 { channel: 'o', length: 25, body: 'test/parsers_spec.coffee\n' },
84 { channel: 'o', length: 2, body: '? ' },
85 { channel: 'o', length: 18, body: 'package.json.orig\n' },
86 { channel: 'r', length: 4, body: 0 } ]
87
88 it "should extract status information", (done) ->
89 states = parsers.status statusData
90 states['lib/parsers.coffee'].should.equal 'A'
91 states['package.json.orig'].should.equal '?'
92 done()