diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2021-01-13 22:50:51 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2021-01-13 22:50:51 +0100 |
commit | 641278c624a3a0c06856656255f648f2cf4f6a92 (patch) | |
tree | 49c47c4c61dd0704e89cfd75681bc16f171e7ad5 | |
parent | Add debug buttons in popup for dumping xcal and jcal. (diff) | |
parent | Document (vcompenent control). (diff) | |
download | calp-641278c624a3a0c06856656255f648f2cf4f6a92.tar.gz calp-641278c624a3a0c06856656255f648f2cf4f6a92.tar.xz |
Merge branch 'doc' into jcal
45 files changed, 803 insertions, 47 deletions
diff --git a/doc/frontend.org b/doc/frontend.org index 0b5725aa..63d6fe1f 100644 --- a/doc/frontend.org +++ b/doc/frontend.org @@ -1,29 +1,5 @@ ** Javascript "components" -*** input-list -file:../static/input_list.js - -All elements having 'input-list' ∈ =class= - -Direct children must all have 'unit' ∈ =class= -One direct child must have 'final' ∈ =class= - -binds =get_value= on instances, by default returning the value -of all =<input/>= tags joined by =,=. This can be overwritten with -- =data-joinby= :: Alternative character to join by -- =data-bindby= :: replacement for get_value - -TODO: instead, override value? - -=addEventList('input',= is overwritten, registering the listener for all input -elements. - *** Popup Handles popup. Currently rather specific -*** Dragable -file:../static/dragable.js - -Manually apply =bind_popup_control= to the statusbar of a floating "window". -Nothing is required from the component, but the "window" must have -'popup-container' ∈ =class= diff --git a/doc/ref/Makefile b/doc/ref/Makefile new file mode 100644 index 00000000..2232a70e --- /dev/null +++ b/doc/ref/Makefile @@ -0,0 +1,7 @@ +TEXI_FILES := $(shell find . -type f -name \*.texi) +INFOFLAGS := + +all: calp.info + +calp.info: $(TEXI_FILES) + makeinfo $(INFOFLAGS) calp.texi diff --git a/doc/ref/calp.texi b/doc/ref/calp.texi new file mode 100644 index 00000000..e5c4baab --- /dev/null +++ b/doc/ref/calp.texi @@ -0,0 +1,71 @@ +\input texinfo +@settitle Calp + +@copying +Copyright @copyright{} 2020 Hugo Hörnquist +@end copying + +@c Borrowed from guile.texi +@c @nicode{S} is plain S in info, or @code{S} elsewhere. This can be used +@c when the quotes that @code{} gives in info aren't wanted, but the +@c fontification in tex or html is wanted. @alias is used rather +@c than @macro because backslashes don't work properly in an @macro. +@ifinfo +@alias nicode=asis +@end ifinfo +@ifnotinfo +@alias nicode=code +@end ifnotinfo + +@c @ifinfo +@c @macro i{text} +@c [3m\text\[0m +@c @end macro +@c @end ifinfo + +@c for use with deftp for extended classes +@macro extends{class} +@w{@i{extends} \class\} +@end macro + +@c For things that should be fixed in the (actual) code. +@c An ``invitation'' to the reader +@macro TODO{text} +text @footnote{Improvements welcome} +@end macro + +@macro githash{hash,path,line} +@url{https://git.hornquist.se/calp/tree/\path\?id=\hash\#n\line\,\hash\} +@end macro + +@titlepage +@title Calp +@author Hugo Hörnquist + +@page +@vskip 0pt plus 1filll +@insertcopying +@end titlepage + +@contents + +@ifnottex +@node Top +@top Calp +@end ifnottex + +@c @menu +@c * Index:: +@c @end menu + +@include guile.texi +@include javascript.texi + +@node Index +@unnumbered Index +@printindex cp +@printindex fn +@printindex tp +@printindex vr + +@bye diff --git a/doc/ref/guile.texi b/doc/ref/guile.texi new file mode 100644 index 00000000..8468021e --- /dev/null +++ b/doc/ref/guile.texi @@ -0,0 +1,17 @@ +@node Guile +@chapter Guile + +@c TODO +This chapter will probably in the future be replaced by a proper +system overview in the future. + +@c module (vcomponent control) + +@defmac with-replaced-properties (component (key value) ...) body ... +Through the extent of @var{body} each @var{key}'s value in +@var{component} is replaced by its repspective @var{value}. + +Note that @var{body} is guarded through a dynamic-wind, meaning that +even non-local exits will restore @var{component} to its initial +state. +@end defmac diff --git a/doc/ref/javascript.texi b/doc/ref/javascript.texi new file mode 100644 index 00000000..6fbd7cdc --- /dev/null +++ b/doc/ref/javascript.texi @@ -0,0 +1,35 @@ +@node Javascript +@chapter Javascript + +@node Concepts +@section Concepts + +@subsection ``Componenents'' + +@deftp {} date_time +@cindex date-time + +@ref{date_time} +@end deftp + +@deftp {} draggable +@end deftp + +@deftp {} input_list +@end deftp + +@node Reference +@section Reference +@include javascript/arbitary_kv.texi +@include javascript/binders.texi +@include javascript/clock.texi +@include javascript/date_time.texi +@include javascript/draggable.texi +@include javascript/input_list.texi +@include javascript/jcal.texi +@include javascript/lib.texi +@include javascript/popup.texi +@include javascript/rrule.texi +@include javascript/script.texi +@include javascript/server_connect.texi +@include javascript/types.texi diff --git a/doc/ref/javascript/arbitary_kv.texi b/doc/ref/javascript/arbitary_kv.texi new file mode 100644 index 00000000..b28c8b92 --- /dev/null +++ b/doc/ref/javascript/arbitary_kv.texi @@ -0,0 +1,3 @@ +@node arbitary_kv +@subsection arbitary_kv.js + diff --git a/doc/ref/javascript/binders.texi b/doc/ref/javascript/binders.texi new file mode 100644 index 00000000..2b64b230 --- /dev/null +++ b/doc/ref/javascript/binders.texi @@ -0,0 +1,47 @@ + +@node binders +@subsection binders.js + +The bind system allows HTML-elements to specify that they want to be +updated whenever its corresponding (vcalendar) object changes. +The bind system is currently set up in +@code{bind_properties} (@pxref{bind_properties}) +(which at the time of writing is (badly) located in @ref{script}). + +All (HTML) components with the class @code{bind} are bound. By default +the (HTML) attribute @code{data-property} is checked for a property +name, and @code{object.innerHTML} is set whenever that property field +changes. +Alternatively an (HTML) component may specify a specific binder +through the HTML attribute @code{data-bindby}, which should be the +name of a JavaScript function taking two arguments, an @TODO{event +component} +@footnote{Root ``root'' HTML component of a given calendar event +(something which @code{get_property} can be called on}, +and the component in question. + +@c Also sets up event listeners, which most doesn't do. + +Binder functions are generally placed in @file{binders.js}, and +shouldn't be called manually. + +@defun bind_recur el e +Handles recurrence rules. +Uses a sub-binder system on components with class containing +``bind-rr''. +@end defun + +@defun bind_edit el e +Cases for @code{input} and @code{textarea} elements @TODO{(should also +handle @code{select}s?)} +@end defun + +@defun bind_view el e +The same as the default binder???? +@end defun + +@defun bind_wholeday el e +Binder for the wholeday toggle button. +While CSS would suffice, this sets the disabled flags on the time +inputs, giving a better user experience. +@end defun diff --git a/doc/ref/javascript/clock.texi b/doc/ref/javascript/clock.texi new file mode 100644 index 00000000..5c2bd954 --- /dev/null +++ b/doc/ref/javascript/clock.texi @@ -0,0 +1,84 @@ +@node clock +@subsection clock.js + +@deftp {(abstract) class} Clock +Interface for ``things'' which wants to get updated on a human timescale. + +@defmethod Clock update now +Called every now and then, with @var{now} being the current time. +@end defmethod + +All instances are expected to implement @code{update}, but are free to +implement any other methods they see fit. +@end deftp + +Below, only the methods (including @code{constructor} and +@code{update} which do something of note (excluding the expected)) +are noted. + +@deftp {class} Timebar @extends{Clock} +The (blue) vertical line which show the current time in the current day. + +@c @defmethod Timebar constructor ∅ +@c @end defmethod +@c +@c @defmethod Timebar update now +@c @end defmethod +@end deftp + +@deftp {class} SmallcalCellHighlight @extends{Clock} +Highlights the current date in the small calendar to the side. +Currently directly sets a border +@TODO{but should preferably set a class instead}. + +@defmethod SmallcalCellHighlight constructor small_cal +@var{small_cal} is the DOM-node of the calendar. +(it should support querySelector). +@end defmethod + +@c @defmethod SmallcalCellHighlight update now +@c @end defmethod +@end deftp + +@deftp {class} ButtonUpdater @extends{Clock} +Updates the ``Today'' link in the side panel to point directly to the +correct web-address. The link works without JavaScript, but then +requires a redirect from the server. + +All actual updating logic is already abstracted away. It would be +desirable if something more was done with this. + +@defmethod ButtonUpdater el proc +Takes the element @var{el} to be updated, and the procedure @var{proc} +which will be called with the element, and the current time. +@end defmethod +@end deftp + + +As of commit +@githash{c9719ce7937f0f0f2aa371ced1d585f67af22457,static/script.js,231} +all objects required manual setup. See static/script.js: + +@verbatim + 231 let start_time = document.querySelector("meta[name='start-time']").content; + 232 let end_time = document.querySelector("meta[name='end-time']").content; + 233 + 234 const button_updater = new ButtonUpdater( + 235 document.getElementById("today-button"), + 236 (e, d) => e.href = d.format('~Y-~m-~d') + ".html" + 237 ); + 238 + 239 const sch = new SmallcalCellHighlight( + 240 document.querySelector('.small-calendar')) + 241 + 242 const timebar = new Timebar(start_time, end_time); + 243 + 244 timebar.update(new Date); + 245 window.setInterval(() => { + 246 let d = new Date; + 247 timebar.update(d); + 248 button_updater.update(d); + 249 sch.update(d); + 250 }, 1000 * 60); + 251 +@end verbatim diff --git a/doc/ref/javascript/date_time.texi b/doc/ref/javascript/date_time.texi new file mode 100644 index 00000000..fb2563f1 --- /dev/null +++ b/doc/ref/javascript/date_time.texi @@ -0,0 +1,39 @@ +@node date_time +@subsection date_time.js + +@defun init_date_time +@c possibly have special index for these +@cindex dummy component +Procedure which initializes the dummy component for date-time input. +When called, finds all elements with class ``date-time'', and makes +them date-time inputs. + +@c <input type='date-time'/> + +The expected HTML form is +@example +<div class="date-time" name="@var{name}"> + <input type="date"/> + <input type="time"/> +</div> +@end example + +Each date-time gets the following fields: + +@defivar date_time value +The current date-time value as a string, +on the form @code{YYYY-mm-ddTHH:MM[:SS]} +(@code{SS} if the underlying time input has it). + +A new date-time can also be set to the field, the same format as above +is expected. +@end defivar + +@defivar date_time name +The ``name'' field of the date-time input. Since @code{name} note that +this is an addition, since name is actually invalid on non-input +components. We nevertheless use it here since we are emulating an +input element. +@end defivar + +@end defun diff --git a/doc/ref/javascript/draggable.texi b/doc/ref/javascript/draggable.texi new file mode 100644 index 00000000..d1851ec4 --- /dev/null +++ b/doc/ref/javascript/draggable.texi @@ -0,0 +1,24 @@ +@node dragable +@subsection dragable.js + +@c TODO This text is just yanked from the old org file, along with the +@c source codes header. It should probably be rewritten. + +Manually apply =bind_popup_control= to the statusbar of a floating +"window". Nothing is required from the component, but the "window" +must have 'popup-container' ∈ =class= + +@defun bind_popup_control nav +Apply to a given component to make it draggable. +Drag area (usually a title bar) should be be the only argument. +It is REQUIRED that the object which should be moved have the class +@code{popup-container}. + +@example +<div class='popup-container'> + ... + <nav /> + ... +</div> +@end example +@end defun diff --git a/doc/ref/javascript/input_list.texi b/doc/ref/javascript/input_list.texi new file mode 100644 index 00000000..65db81a4 --- /dev/null +++ b/doc/ref/javascript/input_list.texi @@ -0,0 +1,51 @@ +@node input_list +@subsection input_list.js +@cindex dummy component + +All elements with the class @code{input-list} are treated as a +collection of input fields. Uses including setting tags on calendar +entries. + +All direct children of the ``input-list'' @emph{must} have the class +@code{unit}, and one direct child @code{unit} have the class @code{final}. + +@c All elements having 'input-list' ∈ =class= + +@c Direct children must all have 'unit' ∈ =class= +@c One direct child must have 'final' ∈ =class= + +@defmethod input_list get_value + +@example +querySelectorAll('input') + .map(x => x.value) + .join(@var{joinby}) +@end example +@end defmethod + +@defivar input_list [data-]joinby + Alternative character to join by +@end defivar + +@defivar input_list [data-]bindby + replacement for get_value +@end defivar + +binds =get_value= on instances, by default returning the value +of all =<input/>= tags joined by =,=. This can be overwritten with + +TODO: instead, override value? + +=addEventList('input',= is overwritten, registering the listener for all input +elements. + + + ∀ children('.input-list') => 'unit' ∈ classList(child) + + <div class="input-list"> + <div class="unit"><input/></div> + <div class="unit final"><input/></div> + </div> + +@defun init_input_list +@end defun diff --git a/doc/ref/javascript/jcal.texi b/doc/ref/javascript/jcal.texi new file mode 100644 index 00000000..4be8d33b --- /dev/null +++ b/doc/ref/javascript/jcal.texi @@ -0,0 +1,4 @@ + +@node jcal +@subsection jcal.js + diff --git a/doc/ref/javascript/lib.texi b/doc/ref/javascript/lib.texi new file mode 100644 index 00000000..ec5d4450 --- /dev/null +++ b/doc/ref/javascript/lib.texi @@ -0,0 +1,147 @@ + +@node lib +@subsection lib.js + +General procedures which in theory could be used anywhere. + +@defvar xcal +The xml namespace name for xcalendar, which is +``urn:ietf:params:xml:ns:icalendar-2.0''. +@end defvar + + +@node Default prototype extensions +@subsubsection Default prototype extensions + +HTMLElement extensions + +@defmethod HTMLElement addEventListener name proc +Replace the default @code{addEventListener} with a version that stores +all listeners in the dictionary @var{listeners}. +@end defmethod + +@defivar HTMLElement listeners +Dictionary of all registered listeners to this element. +Keys are taken from @code{addEventListener}. +@end defivar + +@defmethod DOMTokenList find regexp +Finds the first element of the DOMTokenList whichs value matches +the supplied regexp. Returns a pair of the index and the value. +@end defmethod + +@defmethod Object format args ... +Returns a string representation of the given object. +Allows extending for custom types, +@ref{date-format} +@end defmethod + +@node General +@subsubsection General + +@defun zip args ... +Takes a list of lists, and returns a single list of tuples. +@example +» zip([1,2,3,4,5], "Hello") +← [[1,'H'],[2,'e'],[3,'l'],[4,'l'],[5,'o']] +@end example +@end defun + +@defun makeElement name [attr=@{@}] +Creates a new DOM element of type @var{name}, with all keys in +@var{attr} transfered to it. For example, the equivalent of +@example +<input type='number'/> +@end example +would be +@verbatim +values.push(makeElement('input', { + type: 'number', +})); +@end verbatim +. +@end defun + +@defun round_time time fraction +TODO +@end defun + +@defun date_to_percent date +Retuns how far along the date specified by @var{date} is, between 0 +and 100, where 00:00 maps to 0, and 23:59 to ~100. +@end defun + +@defun gensym [pxrefix='gensym'] +Generates a new string which is (hopefully) globally unique. +Compare with @code{gensym} from Lisp. +@end defun + +@defun setVar str val +Set the CSS var @var{str} to @var{val} on the root element. +@end defun + +@defun asList thing +Ensures that @var{thing} is a list. Returning it outright if it +already is one, otherwise wrapping it in a list. +@end defun + +@node Date +@subsubsection Date + +Some extensions to the builtin class ``Date'' is made. + +@defivar Date utc +Boolean indicating if the given timestamp is in UTC or local time. +true means UTC. +@end defivar + +@defivar Date dateonly +Boolean indicating if the time component of the Date object should be disregarded. +@end defivar + +@defun parseDate str +Takes a string @var{str}, which should be in ISO-8601 date-format, and +returns a javascript Date object. +@end defun + +@defun copyDate date +Creates a new instance of the given Date @var{date}, also transfers my +custom fields. +@end defun + +@defun to_local date +@anchor{to_local} +Returns a Date object (which may be new) which is guaranteed in local +time. +This means that the @var{utc} field is @code{false}, and that +@code{to_local(current_time())} should show what your wall-clock shows. +@end defun + +@defmethod Date format str args ... +@anchor{date-format} +Formats a Date object according to the format specification @var{str}. +Keeping with Guile each format specifier starts with a ~. + +@c table formatting borrowed from Gulie Reference (SRFI-19 Date to string) +@multitable {MMMM} {MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM} +@item @nicode{~~} @tab literal ~ +@c Almost all fields are left padded. How do I signify this +@c with a single footnote? +@item @nicode{~Y} @tab year, left-padding with zeroes. +@item @nicode{~m} @tab month number, left padded with zeroes. +@item @nicode{~d} @tab day of month. +@item @nicode{~H} @tab hour +@item @nicode{~M} @tab minute +@item @nicode{~S} @tab second +@item @nicode{~Z} @tab 'Z' if Date is UTC, otherwise nothing + +@item @nicode{~L} @tab Converts the date to local time +(@pxref{to_local}) (doesn't modify source object). Outputs nothing +@end multitable +@end defmethod + +@defun format_date date str +Equivalent to @code{(@var{date}).format(@var{str})}. +@c TODO link +@end defun + diff --git a/doc/ref/javascript/popup.texi b/doc/ref/javascript/popup.texi new file mode 100644 index 00000000..2dd8f48f --- /dev/null +++ b/doc/ref/javascript/popup.texi @@ -0,0 +1,5 @@ + + +@node popup +@subsection popup.js + diff --git a/doc/ref/javascript/rrule.texi b/doc/ref/javascript/rrule.texi new file mode 100644 index 00000000..5d7a7576 --- /dev/null +++ b/doc/ref/javascript/rrule.texi @@ -0,0 +1,4 @@ + +@node rrule +@subsection rrule.js + diff --git a/doc/ref/javascript/script.texi b/doc/ref/javascript/script.texi new file mode 100644 index 00000000..a60343e4 --- /dev/null +++ b/doc/ref/javascript/script.texi @@ -0,0 +1,60 @@ + +@node script +@subsection script.js + +@dfn{Main} for my javascript, and also currently dumping ground for stuff. + +@deftp {class} EventCreator + +@defmethod EventCreator create_empty_event +@end defmethod + +@defmethod EventCreator create_event_down intended_target +@end defmethod + +@defmethod EventCreator create_event_move pos_in [round=1] [wide_element=false] +@end defmethod + +@defmethod EventCreator create_event_finisher callback +@end defmethod + +@end deftp + +@defun place_in_edit_mode event +@end defun + +@c window.onload is here in source file + +@defun get_property event field default_value +Returns the @emph{value} slot of given field in @var{event}, creating it if needed. + +@itemize +@item +@var{el}: the event to work on + +@item +@var{field}: name of the field + +@item +@var{default_value}: default value when creating + +@item +@var{bind_to_ical} should this property be added to the icalendar subtree? +@end itemize +@end defun + +@defun bind_properties el [wide_event=false] +@anchor{bind_properties} +@ref{binders} + Properties are icalendar properties. + + p['name'] to get and set value (also updates any connected slots) + + p['_value_name'] for raw value + p['_slot_name'] for connected slots, Vector of pairs, where the + car should be a reference to the slot, and the + cdr a procedure which takes a slot and a value + and binds the value to the slot. +@end defun + + diff --git a/doc/ref/javascript/server_connect.texi b/doc/ref/javascript/server_connect.texi new file mode 100644 index 00000000..2f50f02d --- /dev/null +++ b/doc/ref/javascript/server_connect.texi @@ -0,0 +1,2 @@ +@node server_connect +@subsection server_connect.js diff --git a/doc/ref/javascript/types.texi b/doc/ref/javascript/types.texi new file mode 100644 index 00000000..73a58550 --- /dev/null +++ b/doc/ref/javascript/types.texi @@ -0,0 +1,39 @@ +@node types +@subsection types.js + +Collection of type information for calendar data. + +@defvar all_types +Name of all valid icalendar types. + + text, uri, binary, float, integer, date-time, date, duration, + period, utc-offset, cal-address, recur, boolean, +@end defvar + +@defvar property_names +All known names properties (top level keys) can have. +Such as ``calscale'', ``dtstart'', ... +@end defvar + +@defvar valid_fields +Which property fields each component can hold. + +@verbatim +{ 'VCALENDAR': ['PRODID', 'VERSION', 'CALSCALE', 'METHOD'], + ... +} +@end verbatim +@end defvar + +@defvar valid_input_types +Which types are valid to store under each property. +If multiple values are an option for that property, then +the list of possibilities will contain a sub-list (see example). + +@verbatim +{ 'DTSTART': ['date', 'date-time'], + 'CATEGORIES': [['text']], + ... +} +@end verbatim +@end defvar diff --git a/module/calp/html/view/calendar.scm b/module/calp/html/view/calendar.scm index 39f3f635..3f607bb7 100644 --- a/module/calp/html/view/calendar.scm +++ b/module/calp/html/view/calendar.scm @@ -39,7 +39,7 @@ ;;; All this filtering is probably slow, and should be looked into. ;; TODO place this somewhere proper -(define repo-url (make-parameter "https://git.hornquist.se")) +(define repo-url (make-parameter "https://git.hornquist.se/calp")) ;; TODO document what @var{render-calendar} is supposed to take and return. @@ -142,7 +142,7 @@ (footer (@ (style "grid-area: footer")) (span "Page generated " ,(date->string (current-date))) - (span (a (@ (href ,(repo-url) "/calparse")) + (span (a (@ (href ,(repo-url))) "Source Code"))) ;; Small calendar and navigation diff --git a/static/clock.js b/static/clock.js index 40382faa..b7777a08 100644 --- a/static/clock.js +++ b/static/clock.js @@ -16,14 +16,14 @@ class Timebar extends Clock { update(now) { - if (! (this.start_time <= now.getTime() && now.getTime() < this.end_time)) - return; + // if (! (this.start_time <= now.getTime() && now.getTime() < this.end_time)) + // return; var event_area = document.getElementById(now.format("~Y-~m-~d")) if (event_area) { if (this.bar_object) { - this.bar_object.parentNode.removeChild(bar_object) + this.bar_object.parentNode.removeChild(this.bar_object) } else { this.bar_object = makeElement ('div', { id: 'bar', diff --git a/static/input_list.js b/static/input_list.js index 4430154a..a7a446f3 100644 --- a/static/input_list.js +++ b/static/input_list.js @@ -9,6 +9,7 @@ */ +/* private */ function transferListeners(old_unit, new_unit) { for (let [o, n] of zip([old_unit, ...old_unit.querySelectorAll("*")], [new_unit, ...new_unit.querySelectorAll("*")])) { @@ -22,6 +23,7 @@ function transferListeners(old_unit, new_unit) { } +/* private */ function advance_final(input_list) { let old_unit = input_list.unit; let new_unit = old_unit.cloneNode(true); @@ -31,7 +33,7 @@ function advance_final(input_list) { } - +/* private */ function update_inline_list () { /* can target self */ diff --git a/static/script.js b/static/script.js index 596caf6d..6b7ddcd9 100644 --- a/static/script.js +++ b/static/script.js @@ -228,8 +228,8 @@ function place_in_edit_mode (event) { } window.onload = function () { - let start_time = document.querySelector("meta[name='start-time']").content; - let end_time = document.querySelector("meta[name='end-time']").content; + // let start_time = document.querySelector("meta[name='start-time']").content; + // let end_time = document.querySelector("meta[name='end-time']").content; const button_updater = new ButtonUpdater( document.getElementById("today-button"), @@ -239,9 +239,10 @@ window.onload = function () { const sch = new SmallcalCellHighlight( document.querySelector('.small-calendar')) - const timebar = new Timebar(start_time, end_time); + const timebar = new Timebar(/*start_time, end_time*/); timebar.update(new Date); + sch.update(new Date); window.setInterval(() => { let d = new Date; timebar.update(d); diff --git a/tests/base64.scm b/tests/base64.scm index b0bb992a..59a8784c 100644 --- a/tests/base64.scm +++ b/tests/base64.scm @@ -1,6 +1,10 @@ +;;; Commentary: +;; Test that Base64 encoding and decoding works +;; Examples from RFC4648 +;;; Code: + (((base64) base64encode base64decode)) -;; Examples from RFC4648 (test-equal "" (base64encode "")) (test-equal "Zg==" (base64encode "f")) diff --git a/tests/cpp.scm b/tests/cpp.scm index d83ba554..84bd4b92 100644 --- a/tests/cpp.scm +++ b/tests/cpp.scm @@ -1,3 +1,7 @@ +;;; Commentary: +;; Tests my parser for a subset of the C programming language. +;;; Code: + (((c lex) lex) ((c parse) parse-lexeme-tree)) diff --git a/tests/datetime-compare.scm b/tests/datetime-compare.scm index 649dc59f..f2585f46 100644 --- a/tests/datetime-compare.scm +++ b/tests/datetime-compare.scm @@ -1,3 +1,8 @@ +;;; Commentary: +;; Tests that all ordering predicates for dates, +;; times, and datetimes hold. +;;; Code: + (((datetime) date datetime time diff --git a/tests/datetime-util.scm b/tests/datetime-util.scm index 123229c7..28317676 100644 --- a/tests/datetime-util.scm +++ b/tests/datetime-util.scm @@ -1,3 +1,9 @@ +;;; Commentary: +;; Tests timespan overlaps and month-streams. +;; Separate from tests/datetime.scm since +;; (datetime util) originally was its own module. +;;; Code: + (((datetime) date time datetime month-stream in-date-range? timespan-overlaps?) ((srfi srfi-41) stream->list stream-take diff --git a/tests/datetime.scm b/tests/datetime.scm index 83750472..5bf2df6d 100644 --- a/tests/datetime.scm +++ b/tests/datetime.scm @@ -1,3 +1,8 @@ +;;; Commentary: +;; Tests date, time, and datetime creation, +;; (output) formatting, and arithmetic. +;;; Code: + (((datetime) date+ date- time+ time- year month day diff --git a/tests/display b/tests/display new file mode 100755 index 00000000..e58288a2 --- /dev/null +++ b/tests/display @@ -0,0 +1,2 @@ +#!/bin/bash +guild display-commentary *.scm | sed -e 's/^ / /' -e 's/^\S/\n&/g' diff --git a/tests/let.scm b/tests/let.scm index 82919b49..81a34131 100644 --- a/tests/let.scm +++ b/tests/let.scm @@ -1,3 +1,7 @@ +;;; Commentary: +;; Tests my custom let*. +;;; Code: + (((calp util) let*) ((guile) set!)) diff --git a/tests/param.scm b/tests/param.scm index 0c4190dd..23704948 100644 --- a/tests/param.scm +++ b/tests/param.scm @@ -1,3 +1,8 @@ +;;; Commentary: +;; Checks that parameters (1) are correctly parsed and stored. +;; (1): 'A', and 'B' in the line "KEY;A=1;B=2:Some text" +;;; Code: + (((vcomponent base) param prop* parameters) ((vcomponent parse) parse-calendar) ((calp util) sort*)) diff --git a/tests/recurrence-id.scm b/tests/recurrence-id.scm index 601b0f71..be58d924 100644 --- a/tests/recurrence-id.scm +++ b/tests/recurrence-id.scm @@ -1,3 +1,9 @@ +;;; Commentary: +;; Tests that exceptions (in the recurrence-id meaning) +;; in recurrence sets are handled correctly. +;; TODO Is however far from done. +;;; Code: + (((srfi srfi-41) stream->list) ((vcomponent) parse-calendar) ((vcomponent recurrence) generate-recurrence-set) @@ -6,6 +12,23 @@ (define uid (symbol->string (gensym "areallyuniqueid"))) +;; TODO standardize vcomponents for tests as xcal, for example: +`(vcalendar + (children + (vevent + (properties + (summary (text "Changing type on Recurrence-id.")) + (uid (text ,uid)) + (dtstart (date "20090127")))) + (vevent + (properties + (summary (text "Changing type on Recurrence-id.")) + (uid (text ,uid)) + (dtstart (params (TZID "Europe/Stockholm")) + (date-time "20100127T120000")) + (recurrence-id (date "20100127")) + (summary "This instance only has a time component"))))) + (define ev (call-with-input-string (format #f "BEGIN:VCALENDAR diff --git a/tests/recurrence.scm b/tests/recurrence.scm index 6ced6af0..ceab07cd 100644 --- a/tests/recurrence.scm +++ b/tests/recurrence.scm @@ -1,9 +1,17 @@ ;;; Commentary: +;; Advanced tests of "generate-recurrence-set", along with +;; format-recurrence-rule which checks that human readable +;; representations of the RRULES work. +;; +;; Also contains the tests for EXDATE. +;; +;; Examples copied from RFC5545 +;;; Code: + ;; The human readable tests are expected to fail with any change to the ;; text creator. Proof-read them manually, and update the test cases ;; to match. `x-summary' used for target string. Target strings should ;; be in swedish. -;;; Code: (((vcomponent recurrence parse) parse-recurrence-rule) ((vcomponent recurrence generate) generate-recurrence-set) @@ -16,8 +24,6 @@ ((srfi srfi-41) stream->list) ((srfi srfi-88) keyword->string)) -;; Examples copied from RFC5545 - (define (run-test comp) (test-equal (string-append "RSET: " (prop comp 'SUMMARY)) diff --git a/tests/recurring.scm b/tests/recurring.scm index a3f98027..d677971e 100644 --- a/tests/recurring.scm +++ b/tests/recurring.scm @@ -1,3 +1,7 @@ +;;; Commentary: +;; General tests of "generate-recurrence-set". +;;; Code: + (((srfi srfi-41) stream-take stream-map stream->list stream-car) ((datetime) day-stream) ((vcomponent base) extract prop) diff --git a/tests/rrule-parse.scm b/tests/rrule-parse.scm index b7a851a0..e2990cbc 100644 --- a/tests/rrule-parse.scm +++ b/tests/rrule-parse.scm @@ -1,3 +1,8 @@ +;;; Commentary: +;; Basic tests that recurrence rule parsing works. +;; Including that it fails on invalid output. +;;; Code: + (((vcomponent recurrence parse) parse-recurrence-rule) ((vcomponent recurrence) make-recur-rule) diff --git a/tests/run-tests.scm b/tests/run-tests.scm index 670a1784..4060a170 100755 --- a/tests/run-tests.scm +++ b/tests/run-tests.scm @@ -2,6 +2,13 @@ -s !# +;;; Commentary: +;; Not a test, but a script that runs tests. +;; Assumes that all other .scm files in this directory are test files, +;; and should thereby follow the test-file syntax. +;; TODO document the testfile syntax. +;;; Code: + (eval-when (compile load) (define here (dirname (current-filename)))) diff --git a/tests/server.scm b/tests/server.scm index a9cb870e..706697f6 100644 --- a/tests/server.scm +++ b/tests/server.scm @@ -1,6 +1,21 @@ -(((web http make-routes) parse-endpoint-string)) +;;; Commentary: +;; Tests parse-endpoint-string, used for defining server routes. +;;; Code: -(test-assert (parse-endpoint-string "/static/:dir/:file")) -;; => "/static/([^/]+)/([^/]+)" -;; => (dir file) +(((web http make-routes) parse-endpoint-string) + ((calp util) let*)) +(test-assert "Check that parsing doesn't crash" + (parse-endpoint-string "/static/:dir/:file")) + +;; Checks that parsing produces correct results +(let* ((path args (parse-endpoint-string "/static/:dir/:file"))) + (test-equal "/static/([^/]+)/([^/]+)" path) + (test-equal '(dir file) args)) + + +;; Checks that parsing with custom regex works +;; along with literal periods. +(let* ((path args (parse-endpoint-string "/static/:filename{.*}.:ext"))) + (test-equal "/static/(.*)\\.([^/.]+)" path) + (test-equal '(filename ext) args)) diff --git a/tests/srfi-41-util.scm b/tests/srfi-41-util.scm index 61bce71e..3c2c3f0f 100644 --- a/tests/srfi-41-util.scm +++ b/tests/srfi-41-util.scm @@ -1,3 +1,8 @@ +;;; Commentary: +;; Tests (srfi srfi-41 util). +;; Currently only tests stream-paginate. +;;; Code: + (((srfi srfi-41 util) stream-paginate) ((srfi srfi-41) stream->list stream-ref stream-from stream-filter stream-car stream) diff --git a/tests/termios.scm b/tests/termios.scm index 214a12a0..c0cb4323 100755..100644 --- a/tests/termios.scm +++ b/tests/termios.scm @@ -1,10 +1,8 @@ ;;; Commentary: - ;; Tests that my termios function works, at least somewhat. -;; Note that this actually modifies the terminal it's run on, and might fail if -;; the terminal doesn't support the wanted modes. See termios(3). +;; Note that this actually modifies the terminal it's run on, and might fail +;; if the terminal doesn't support the wanted modes. See termios(3). ;; It might also leave the terminal in a broken state if exited prematurely. - ;;; Code: (((calp util) set!) diff --git a/tests/tz.scm b/tests/tz.scm index 8ccd636d..147f0807 100644 --- a/tests/tz.scm +++ b/tests/tz.scm @@ -1,3 +1,11 @@ +;;; Commentary: +;; Tests that datetime->unix-time correctly converts between Olssen +;; timezone definitions (e.g. Europe/Stockholm), into correct times +;; and offsets (in unix time). +;; Also indirectly tests the Zone Info Compiler (datetime zic), since +;; the zoneinfo comes from there. +;;; Code: + (((datetime) parse-ics-datetime datetime date time diff --git a/tests/util.scm b/tests/util.scm index f917b5ce..ed5abfd1 100644 --- a/tests/util.scm +++ b/tests/util.scm @@ -1,3 +1,7 @@ +;;; Commentary: +;; Checks some prodecuders from (calp util) +;;; Code: + (((calp util) filter-sorted set/r!)) (test-equal "Filter sorted" diff --git a/tests/vcomponent-control.scm b/tests/vcomponent-control.scm index 8cc87a0a..2ee4c243 100644 --- a/tests/vcomponent-control.scm +++ b/tests/vcomponent-control.scm @@ -1,3 +1,7 @@ +;;; Commentary: +;; Tests that with-replaced-properties work. +;;; Code: + (((vcomponent control) with-replaced-properties) ((vcomponent) parse-calendar) ((vcomponent base) prop)) diff --git a/tests/vcomponent-datetime.scm b/tests/vcomponent-datetime.scm index f7bb00f4..0bc584f6 100644 --- a/tests/vcomponent-datetime.scm +++ b/tests/vcomponent-datetime.scm @@ -1,3 +1,8 @@ +;;; Commentary: +;; Tests that event-clamping (checking how long part of an event +;; overlaps another time span) works. +;;; Code: + (((datetime) date time datetime) @@ -13,10 +18,15 @@ DTEND:20200401T100000 END:VEVENT" parse-calendar)) +;; |-----------------| test interval +;; |----------| event interval (test-equal "Correct clamping" - (datetime time: (time hour: 7)) - (event-length/clamped #2020-03-23 #2020-03-29 ev)) + (datetime time: (time hour: 7)) ; 2020-03-29T17:00 - 2020-03-30T00:00 + (event-length/clamped + #2020-03-23 ; a time way before the start of the event + #2020-03-29 ; a time slightly after the end of the event + ev)) (define utc-ev (call-with-input-string "BEGIN:VEVENT diff --git a/tests/vcomponent.scm b/tests/vcomponent.scm index 0d81ab0e..15c83845 100644 --- a/tests/vcomponent.scm +++ b/tests/vcomponent.scm @@ -1,3 +1,7 @@ +;;; Commentary: +;; Test that vcomponent parsing works at all. +;;; Code: + (((vcomponent base) prop) ((vcomponent) parse-calendar)) diff --git a/tests/web-server.scm b/tests/web-server.scm index 6b315319..bce05d0e 100644 --- a/tests/web-server.scm +++ b/tests/web-server.scm @@ -1,3 +1,8 @@ +;;; Commentary: +;; Checks that HTTP server can start correctly, and that at least some +;; endpoints return correct information. +;;; Code: + (((calp server routes) make-make-routes) ((web server) run-server) ((ice-9 threads) call-with-new-thread cancel-thread) diff --git a/tests/xcal.scm b/tests/xcal.scm index 1748cba3..babb2218 100644 --- a/tests/xcal.scm +++ b/tests/xcal.scm @@ -1,3 +1,8 @@ +;;; Commentary: +;; Basic tests of xcal convertion. +;; Currently only checks that events survive a round trip. +;;; Code: + (((vcomponent xcal parse) sxcal->vcomponent) ((vcomponent xcal output) vcomponent->sxcal) ((vcomponent ical parse) parse-calendar) |