Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
lib-ical
Commits
6b029687
Commit
6b029687
authored
Feb 21, 2017
by
Mark Stenglein
Browse files
🎉
🎉
It works!
🎉
🎉
parent
a7b64bc0
Pipeline
#928
passed with stage
in 16 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/ContentLine.ts
View file @
6b029687
import
{
isAlpha
}
from
"
./util
"
;
import
{
ICalElement
}
from
"
./ICalElement
"
;
import
Parameter
from
"
./Parameter
"
;
const
CRLF
:
string
=
"
/r/n
"
;
function
isIamaToken
(
input
:
string
):
boolean
{
return
true
;
}
const
CRLF
:
string
=
"
\r\n
"
;
/**
* Implementation of a Content Line from RFC 5545
...
...
@@ -47,7 +44,7 @@ export default class ContentLine implements ICalElement {
/* Setters */
set
name
(
newName
:
string
)
{
if
(
isIa
m
aToken
(
newName
))
{
if
(
Parameter
.
isIa
n
aToken
(
newName
))
{
this
.
_name
=
newName
;
}
else
{
...
...
@@ -59,6 +56,9 @@ export default class ContentLine implements ICalElement {
if
(
isAlpha
(
newValue
))
{
this
.
_value
=
newValue
;
}
else
{
throw
new
TypeError
(
"
'value' must be alphabetic!
"
);
}
}
/**
...
...
@@ -82,7 +82,7 @@ export default class ContentLine implements ICalElement {
this
.
params
.
forEach
((
param
)
=>
{
outputLine
+=
"
;
"
;
outputLine
+=
param
;
outputLine
+=
param
.
generate
()
;
});
outputLine
+=
"
:
"
+
this
.
value
+
CRLF
;
...
...
src/Parameter.ts
View file @
6b029687
...
...
@@ -46,7 +46,7 @@ export default class Parameter implements ICalElement {
get
paramValues
()
{
return
this
.
paramValues
;
return
this
.
_
paramValues
;
}
...
...
@@ -73,7 +73,7 @@ export default class Parameter implements ICalElement {
this
.
_paramName
=
newName
;
}
else
{
throw
new
TypeError
(
"
Parameter must be valid ia
m
a-token or x-
token
"
);
throw
new
TypeError
(
"
Parameter must be valid ia
n
a-token or x-
name
"
);
}
}
...
...
@@ -125,7 +125,7 @@ export default class Parameter implements ICalElement {
* @returns string Representation of the Parameter as defined in RFC 5545
*/
public
generate
():
string
{
let
outputString
=
this
.
paramName
;
let
outputString
=
this
.
paramName
+
"
=
"
;
/**
* Goes through each parameter value and adds it, being sure to place
* the comma for the 2nd parameter onwards.
...
...
@@ -177,7 +177,10 @@ export default class Parameter implements ICalElement {
* TODO: Implement this!
*/
public
static
isXName
(
input
:
string
):
boolean
{
return
true
;
if
(
!
(
input
.
substring
(
0
,
2
)
===
"
X-
"
))
{
return
false
;
}
return
/^
[
a-zA-Z0-9-
]
+$/
.
test
(
input
);
}
/**
...
...
test/ContentLine.spec.ts
View file @
6b029687
...
...
@@ -65,13 +65,13 @@ describe("ContentLine", () => {
it
(
"
Should have the same value as given on input
"
,
()
=>
{
const
testValue
:
string
=
"
testValue
"
;
const
testParam
:
Parameter
=
new
Parameter
(
"
name
"
,
[
testValue
]);
const
testParam
:
Parameter
=
new
Parameter
(
"
NAME
"
,
[
"
TEST
"
]);
const
testLine
:
ContentLine
=
new
ContentLine
(
"
name
"
,
[
testParam
],
testValue
);
const
result
:
string
=
testLine
.
params
[
0
].
paramValues
[
0
]
;
const
result
:
string
=
testLine
.
value
;
expect
(
result
).
to
.
be
.
equal
(
testValue
);
});
});
/*
*
describe("constructor") */
});
/* describe("constructor") */
/**
* Test `fold` static method
...
...
test/Parameter.spec.ts
View file @
6b029687
...
...
@@ -26,8 +26,11 @@ describe("Parameter", () => {
const
testName
:
string
=
"
TEST-NAME
"
;
const
testParam
:
Parameter
=
new
Parameter
(
testName
,
[
"
value1
"
]);
expect
(
testParam
).
to
.
have
.
property
(
"
paramName
"
,
"
paramValues
"
,
"
generate
"
);
expect
(
testParam
).
to
.
have
.
property
(
"
_paramName
"
);
expect
(
testParam
).
to
.
have
.
property
(
"
_paramValues
"
);
expect
(
testParam
).
to
.
have
.
property
(
"
paramName
"
);
expect
(
testParam
).
to
.
have
.
property
(
"
paramValues
"
);
expect
(
testParam
).
to
.
have
.
property
(
"
generate
"
);
});
});
...
...
@@ -99,12 +102,11 @@ describe("Parameter", () => {
const
name
:
string
=
"
!NVALID-N@ME
"
;
const
values
:
string
[]
=
[
"
value
"
];
const
testParam
:
Parameter
=
new
Parameter
(
name
,
values
);
}).
to
.
throw
(
"
param-value must either be valid paramtext or
"
+
"
quoted-string
"
);
}).
to
.
throw
(
"
Parameter must be valid iana-token or x-name
"
);
});
});
describe
(
"
paramValues
"
,
()
=>
{
describe
(
"
***
paramValues
"
,
()
=>
{
it
(
"
Correctly sets paramtext values
"
,
()
=>
{
});
...
...
@@ -132,7 +134,7 @@ describe("Parameter", () => {
* that the higher level classes can simply validate proper types and use
* the lower level generate method.
*/
describe
(
"
generate()
"
,
()
=>
{
describe
(
"
***
generate()
"
,
()
=>
{
it
(
"
Correctly generates single-valued parameters
"
,
()
=>
{
});
...
...
@@ -349,7 +351,6 @@ describe("Parameter", () => {
it
(
"
returns true for valid quoted-string
"
,
()
=>
{
const
test
:
string
=
"
\"
Test this valid quote-string!
\"
"
;
console
.
log
(
test
);
const
result
:
boolean
=
Parameter
.
isQuotedString
(
test
);
expect
(
result
).
to
.
be
.
true
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment