1 | require('lazy-ass');
|
2 | var check = require('check-more-types');
|
3 |
|
4 | describe('utils', function () {
|
5 | var utils = require('./utils');
|
6 |
|
7 | describe('first line', function () {
|
8 | var firstLine = utils.firstLine;
|
9 |
|
10 | it('returns the only line', function () {
|
11 | var line = 'hi there';
|
12 | var first = firstLine(line);
|
13 | la(first === line, 'line has not changed', first);
|
14 | });
|
15 |
|
16 | it('returns the first line from multiline', function () {
|
17 | var text = 'hi there\nsecond line';
|
18 | var first = firstLine(text);
|
19 | la(first === 'hi there', 'only the first line', first, 'from', text);
|
20 | });
|
21 | });
|
22 |
|
23 | describe('trimming tags and versions', function () {
|
24 | var trim = utils.trimVersion;
|
25 |
|
26 | it('passes semver', function () {
|
27 | var tag = '3.0.0';
|
28 | var trimmed = trim(tag);
|
29 | la(trimmed === tag, 'unchanged semver', trimmed, 'from', tag);
|
30 | });
|
31 |
|
32 | it('removes leading v', function () {
|
33 | var tag = 'v3.0.0';
|
34 | var trimmed = trim(tag);
|
35 | la(trimmed === '3.0.0', 'removed leading v from', trimmed, 'from', tag);
|
36 | });
|
37 | });
|
38 |
|
39 | describe('is github user / repo pair', function () {
|
40 | var isGithubName = utils.isGithubName;
|
41 |
|
42 | it('rejects simple word', function () {
|
43 | la(!isGithubName('foo'));
|
44 | });
|
45 |
|
46 | it('rejects multiple words', function () {
|
47 | la(!isGithubName('foo/bar/baz'));
|
48 | });
|
49 |
|
50 | it('detects user / repo', function () {
|
51 | la(isGithubName('foo/bar'));
|
52 | });
|
53 |
|
54 | it('detects user / repo with dashes', function () {
|
55 | la(isGithubName('foo-bar/baz'));
|
56 | });
|
57 |
|
58 | it('detects user / repo with dashes and digits', function () {
|
59 | la(isGithubName('foo-bar/baz-21'));
|
60 | });
|
61 | });
|
62 |
|
63 | describe('parsing github user/repo pair', function () {
|
64 | var parseGithubName = utils.parseGithubName;
|
65 |
|
66 | it('detects user / repo', function () {
|
67 | var result = parseGithubName('foo/bar');
|
68 | la(result.user === 'foo', 'username', result);
|
69 | la(result.repo === 'bar', 'reponame', result);
|
70 | });
|
71 |
|
72 | it('detects user / repo with dashes', function () {
|
73 | var result = parseGithubName('foo-21/bar-baz');
|
74 | la(result.user === 'foo-21', 'username', result);
|
75 | la(result.repo === 'bar-baz', 'reponame', result);
|
76 | });
|
77 | });
|
78 |
|
79 | describe('parse github url', function () {
|
80 | var parse = utils.parseGithubUrl;
|
81 |
|
82 | it('parses example .git', function () {
|
83 | var url = 'https://github.com/bahmutov/next-update.git';
|
84 | var info = parse(url);
|
85 | la(check.object(info), 'not an object', info);
|
86 | la(check.has(info, 'user'), 'missing user', info);
|
87 | la(check.has(info, 'repo'), 'missing repo', info);
|
88 |
|
89 | la(info.user === 'bahmutov', 'wrong user', info);
|
90 | la(info.repo === 'next-update', 'wrong repo', info);
|
91 | });
|
92 |
|
93 | it('parses example without .git', function () {
|
94 | var url = 'https://github.com/chalk/chalk';
|
95 | var info = parse(url);
|
96 | la(info.user === 'chalk', 'wrong user', info);
|
97 | la(info.repo === 'chalk', 'wrong repo', info);
|
98 | });
|
99 |
|
100 | it('parses git@ urls', function () {
|
101 | var url = 'git@github.com:kensho/ng-describe.git';
|
102 | var info = parse(url);
|
103 | la(info.user === 'kensho', 'wrong user', info);
|
104 | la(info.repo === 'ng-describe', 'wrong repo', info);
|
105 | });
|
106 |
|
107 | });
|
108 | });
|