UNPKG

4.07 kBJavaScriptView Raw
1var Assert = require("assert");
2var Base = require("./../lib/shared/base");
3
4var jsDAV_FS_Directory = require("./../lib/DAV/backends/fs/directory");
5var jsDAV_FS_File = require("./../lib/DAV/backends/fs/file");
6
7// interfaces for directories:
8var jsDAV_Collection = require("./../lib/DAV/collection");
9var jsDAV_iQuota = require("./../lib/DAV/interfaces/iQuota");
10var jsDAV_iCollection = require("./../lib/DAV/interfaces/iCollection");
11
12// interfaces for directories:
13var jsDAV_File = require("./../lib/DAV/file");
14var jsDAV_iFile = require("./../lib/DAV/interfaces/iFile");
15
16// interfaces that have nothing to do with files or directories:
17var jsDAV_iHref = require("./../lib/DAV/interfaces/iHref");
18
19// test dir properties
20var dir = jsDAV_FS_Directory.new("somepath/to/a/dir");
21Assert.ok(dir.hasFeature(jsDAV_Collection));
22Assert.ok(dir.hasFeature(jsDAV_iQuota));
23Assert.ok(dir.hasFeature(jsDAV_iCollection));
24
25Assert.ok(dir.UUIDS, dir.UUID & jsDAV_File.UUID, !dir.hasFeature(jsDAV_File));
26Assert.ok(!dir.hasFeature(jsDAV_iFile));
27Assert.ok(!dir.hasFeature(jsDAV_iHref));
28
29// test file properties
30var file = jsDAV_FS_File.new("somepath/to/a/file");
31Assert.ok(file.hasFeature(jsDAV_File));
32Assert.ok(file.hasFeature(jsDAV_iFile));
33
34Assert.ok(!file.hasFeature(jsDAV_Collection));
35Assert.ok(!file.hasFeature(jsDAV_iQuota));
36Assert.ok(!file.hasFeature(jsDAV_iCollection));
37Assert.ok(!file.hasFeature(jsDAV_iHref));
38
39// re-test dir properties
40Assert.ok(dir.hasFeature(jsDAV_Collection));
41Assert.ok(dir.hasFeature(jsDAV_iQuota));
42Assert.ok(dir.hasFeature(jsDAV_iCollection));
43
44Assert.ok(!dir.hasFeature(jsDAV_File));
45Assert.ok(!dir.hasFeature(jsDAV_iFile));
46Assert.ok(!dir.hasFeature(jsDAV_iHref));
47
48// Basic test (form the documentation of Base)
49// ### Object composition ###
50
51var HEX = Base.extend({
52 hex: function hex() {
53 return "#" + this.color;
54 }
55});
56
57var RGB = Base.extend({
58 red: function red() {
59 return parseInt(this.color.substr(0, 2), 16);
60 },
61 green: function green() {
62 return parseInt(this.color.substr(2, 2), 16);
63 },
64 blue: function blue() {
65 return parseInt(this.color.substr(4, 2), 16);
66 }
67});
68
69var CMYK = Base.extend(RGB, {
70 black: function black() {
71 var color = Math.max(Math.max(this.red(), this.green()), this.blue());
72 return (1 - color / 255).toFixed(4);
73 },
74 cyan: function cyan() {
75 var K = this.black();
76 return (((1 - this.red() / 255).toFixed(4) - K) / (1 - K)).toFixed(4);
77 },
78 magenta: function magenta() {
79 var K = this.black();
80 return (((1 - this.green() / 255).toFixed(4) - K) / (1 - K)).toFixed(4);
81 },
82 yellow: function yellow() {
83 var K = this.black();
84 return (((1 - this.blue() / 255).toFixed(4) - K) / (1 - K)).toFixed(4);
85 }
86});
87
88var Color = Base.extend(HEX, RGB, CMYK, {
89 initialize: function Color(color) {
90 this.color = color;
91 }
92});
93
94// ### Prototypal inheritance ###
95
96var Pixel = Color.extend({
97 initialize: function Pixel(x, y, hex) {
98 Color.initialize.call(this, hex);
99 this.x = x;
100 this.y = y;
101 },
102 toString: function toString() {
103 return this.x + ":" + this.y + "@" + this.hex();
104 }
105});
106
107var pixel = Pixel.new(11, 23, "CC3399");
108Assert.equal(pixel.toString(), "11:23@#CC3399");
109
110Assert.equal(pixel.red(), 204);
111Assert.equal(pixel.green(), 51);
112Assert.equal(pixel.blue(), 153);
113
114Assert.equal(pixel.cyan(), 0.0000);
115Assert.equal(pixel.magenta(), 0.7500);
116Assert.equal(pixel.yellow(), 0.250);
117
118// an instance of Color should contain the following objects:
119var color = Color.new("CC3399");
120Assert.ok(color.hasFeature(HEX)); // true
121Assert.ok(color.hasFeature(RGB)); // true
122Assert.ok(color.hasFeature(CMYK)); // true
123Assert.ok(color.hasFeature(Color)); // true
124Assert.ok(!color.hasFeature(Pixel)); // false
125
126// an instance of Pixel should contain the following objects:
127var pixel = Pixel.new(11, 23, "CC3399");
128Assert.ok(pixel.hasFeature(HEX)); // true
129Assert.ok(pixel.hasFeature(RGB)); // true
130Assert.ok(pixel.hasFeature(CMYK)); // true
131Assert.ok(pixel.hasFeature(Color)); // true