{"size": 1278, "ext": "js", "max_stars_repo_path": "test.js", "max_stars_repo_name": "dontcallmedom/node-domain-name-parser", "max_stars_repo_stars_event_min_datetime": "2015-05-21T17:28:43.000Z", "max_stars_repo_stars_event_max_datetime": "2019-09-26T14:20:34.000Z", "max_issues_repo_path": "test.js", "max_issues_repo_name": "dontcallmedom/node-domain-name-parser", "max_issues_repo_issues_event_min_datetime": "2015-02-04T19:57:59.000Z", "max_issues_repo_issues_event_max_datetime": "2021-06-01T07:37:48.000Z", "max_forks_repo_path": "test.js", "max_forks_repo_name": "dontcallmedom/node-domain-name-parser", "max_forks_repo_forks_event_min_datetime": "2015-05-26T15:05:41.000Z", "max_forks_repo_forks_event_max_datetime": "2015-05-26T15:05:41.000Z"}
{"max_stars_count": 5, "max_issues_count": 156, "max_forks_count": 1, "avg_line_length": 31.1707317073, "max_line_length": 97, "alphanum_fraction": 0.5884194053}
var expect = require("expect.js")
var domainNameParser = require("./index.js");

var buildDomainNameDataObj = function (components) {
    var tld = components[0];
    var sld = components[1];
    var sub = components[2] || "";
    return {tld: tld, sld: sld, subdomain: sub};

};

var tests = [
    {desc: "simple domain name", inp: "www.example.org",
     out: ["org", "example", "www"]
    },
    {desc: "simple domain name, no subdomain", inp: "example.org",
     out: ["org", "example"]
    },
    {desc: "multiple subdomain", inp: "we.love.subdomains.example.org",
     out: ["org", "example", "we.love.subdomains"]
    },
    {desc: "long tld", inp: "www.example.ap-southeast-2.amazonaws.com",
     out: ["ap-southeast-2.amazonaws.com", "example", "www"]
    },
    {desc: "I18N tld", inp: "www.example.娱乐",
     out: ["娱乐", "example", "www"]
    },
    {desc: "unknown tld", inp: "www.example.qsdfjqsldfkjqmlsdkjf",
     out: ["qsdfjqsldfkjqmlsdkjf", "example", "www"]
    },

];

tests.forEach(function (test) {
    describe('Testing ' + test.desc + ' ' + test.inp, function () {
        it('should parse ' + test.inp + ' correclty', function () {
            expect(domainNameParser.parse(test.inp)).to.be.eql(buildDomainNameDataObj(test.out));
        });
    });
});
