summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2025-10-24 22:41:32 -0500
committerCraig Jennings <c@cjennings.net>2025-10-24 22:41:32 -0500
commit11d54d0b985db98ecdfce838a3e5dabb59f0e95e (patch)
tree778d1cc0c4924185367a05401ce094a727a21767
moving back to github
-rw-r--r--COPYING674
-rw-r--r--README.org350
-rw-r--r--chime.el720
-rw-r--r--sounds/chime.wavbin0 -> 156716 bytes
-rw-r--r--tests/test-chime-apply-blacklist.el292
-rw-r--r--tests/test-chime-apply-whitelist.el283
-rw-r--r--tests/test-chime-check-event.el185
-rw-r--r--tests/test-chime-extract-time.el388
-rw-r--r--tests/test-chime-has-timestamp.el227
-rw-r--r--tests/test-chime-notification-text.el204
-rw-r--r--tests/test-chime-notifications.el227
-rw-r--r--tests/test-chime-notify.el244
-rw-r--r--tests/test-chime-time-left.el222
-rw-r--r--tests/test-chime-timestamp-parse.el321
-rw-r--r--tests/test-chime-timestamp-within-interval-p.el280
-rw-r--r--tests/test-chime-update-modeline.el204
-rw-r--r--tests/testing-strategy.org319
-rw-r--r--tests/testutil-general.el184
18 files changed, 5324 insertions, 0 deletions
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..e72bfdd
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,674 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ <program> Copyright (C) <year> <name of author>
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<https://www.gnu.org/licenses/>.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+<https://www.gnu.org/licenses/why-not-lgpl.html>. \ No newline at end of file
diff --git a/README.org b/README.org
new file mode 100644
index 0000000..dc2c7e3
--- /dev/null
+++ b/README.org
@@ -0,0 +1,350 @@
+
+* *CHIME Heralds Imminent Events*
+
+Customizable org notifications for Emacs with visual alerts, audible chimes, and modeline display.
+
+** About
+
+CHIME (backronym: *CHIME Heralds Imminent Events*) provides notification support for your org-agenda events. Get visual notifications, a pleasant chime sound, and see your next upcoming event in your modeline.
+
+This is an updated and maintained fork of the abandoned [[https://github.com/akhramov/org-wild-notifier.el][org-wild-notifier]] project, renamed to CHIME with bug-fixes and new features.
+
+Note: while I've found this package to be quite reliable, it's still undergoing feature development and will be changing frequently.
+
+** Features
+
+- *Visual notifications* with customizable alert times
+- *Audible chime sound* when notifications are displayed.
+- *Modeline display* of next upcoming event with customizable lookahead
+- Multiple notification times per event (e.g., 5 minutes before and at event time)
+- Works with SCHEDULED and DEADLINE and plain timestamps
+- Supports repeating timestamps (=+1w=, =.+1d=, =++1w=)
+- Per-event notification customization via properties
+- Async background checking (runs every minute)
+- Configurable notification filtering by keywords and tags
+- [[tests/testing-strategy.org][Well-tested]], including with org-gcal
+
+** Installation
+
+This package is NOT YET available on MELPA.
+
+*** package-vc-install (Emacs 29+)
+
+#+BEGIN_SRC elisp
+(unless (package-installed-p 'chime)
+ (package-vc-install "https://github.com/cjennings/chime.el"))
+#+END_SRC
+
+*** use-package with :vc (Emacs 29+)
+
+#+BEGIN_SRC elisp
+(use-package chime
+ :vc (:url "https://github.com/cjennings/chime.el" :rev :newest)
+ :after (alert org-agenda)
+ :commands (chime-mode chime-check)
+ :bind ("C-c A" . chime-check)
+ :config
+ ;; Notification times: 5 minutes before and at event time
+ (setq chime-alert-time '(5 0))
+
+ ;; Chime sound
+ (setq chime-play-sound t)
+
+ ;; Modeline display
+ (setq chime-modeline-lookahead 30)
+ (setq chime-modeline-format " ⏰ %s")
+
+ ;; Notification settings
+ (setq chime-notification-title "Reminder")
+ (setq chime-alert-severity 'medium)
+
+ ;; Don't filter by TODO keywords - notify for all events
+ (setq chime-keyword-whitelist nil)
+ (setq chime-keyword-blacklist nil)
+
+ ;; Only notify for non-done items
+ (setq chime-predicate-blacklist
+ '(chime-done-keywords-predicate))
+
+ ;; Enable chime-mode automatically
+ (chime-mode 1))
+#+END_SRC
+
+*** Manual Installation (Recommended for Development)
+
+#+BEGIN_SRC elisp
+;; Add to load-path
+(add-to-list 'load-path "~/path/to/chime.el")
+
+;; Load and configure
+(require 'chime)
+#+END_SRC
+
+** Quick Start
+
+Minimal configuration:
+
+clone the package somewhere, then add
+
+#+BEGIN_SRC elisp
+ (add-to-list 'load-path "/path/to/chime.el/")
+ (require 'chime)
+
+ ;; Notify 5 minutes before and at event time
+ (setq chime-alert-time '(5 0))
+
+ ;; Enable notifications
+ (chime-mode 1)
+#+END_SRC
+
+** Configuration
+
+*** Alert Times
+
+Set when to receive notifications (in minutes before event):
+
+#+BEGIN_SRC elisp
+;; Single notification 10 minutes before
+(setq chime-alert-time 10)
+
+;; Multiple notifications: 10 min, 5 min, and at event time
+(setq chime-alert-time '(10 5 0))
+#+END_SRC
+
+*** Chime Sound
+
+Control the audible chime that plays when notifications appear:
+
+#+BEGIN_SRC elisp
+;; Enable/disable chime sound (default: t)
+(setq chime-play-sound t)
+
+;; Use custom sound file (defaults to bundled chime.wav)
+(setq chime-sound-file "/path/to/your/chime.wav")
+
+;; Disable sound, use system beep instead
+(setq chime-sound-file nil)
+#+END_SRC
+
+The package includes a pleasant chime sound in GPL-compatible WAV format. You can use your own sound file if preferred.
+
+*** Modeline Display
+
+Show the next upcoming event in your modeline:
+
+#+BEGIN_SRC elisp
+;; Show events up to 30 minutes ahead (default)
+(setq chime-modeline-lookahead 30)
+
+;; Customize the display format (default: " ⏰ %s")
+(setq chime-modeline-format " [Next: %s]")
+
+;; Disable modeline display
+(setq chime-modeline-lookahead 0)
+#+END_SRC
+
+The modeline will display the soonest event within the lookahead window, formatted as:
+- Default: =⏰ Meeting with Team at 02:30 PM (in 15 minutes)=
+- Updates automatically every minute
+
+*** Notification Settings
+
+#+BEGIN_SRC elisp
+;; Notification title
+(setq chime-notification-title "Reminder")
+
+;; Notification severity (low, medium, high)
+(setq chime-alert-severity 'medium)
+#+END_SRC
+
+*** Filtering
+
+#+BEGIN_SRC elisp
+;; Only notify for specific TODO keywords
+(setq chime-keyword-whitelist '("TODO" "NEXT"))
+
+;; Never notify for these keywords
+(setq chime-keyword-blacklist '("DONE" "CANCELLED"))
+
+;; Only notify for specific tags
+(setq chime-tags-whitelist '("@important"))
+
+;; Never notify for these tags
+(setq chime-tags-blacklist '("someday"))
+#+END_SRC
+
+** Usage
+
+*** Basic Event with Timestamp
+
+#+BEGIN_SRC org
+,* Meeting with Team
+<2025-10-25 Sat 14:00>
+#+END_SRC
+
+Will notify at 14:00 (if =chime-alert-time= includes =0=).
+
+*** Events with SCHEDULED or DEADLINE
+
+#+BEGIN_SRC org
+,* TODO Call Doctor
+SCHEDULED: <2025-10-25 Sat 10:00>
+#+END_SRC
+
+*** Repeating Events
+
+Repeating timestamps are fully supported:
+
+#+BEGIN_SRC org
+,* TODO Weekly Team Meeting
+SCHEDULED: <2025-10-25 Sat 14:00 +1w>
+
+,* TODO Daily Standup
+SCHEDULED: <2025-10-25 Sat 09:00 +1d>
+
+,* TODO Review Email
+SCHEDULED: <2025-10-25 Sat 08:00 .+1d>
+#+END_SRC
+
+Supported repeaters:
+- =+1w= - Repeat weekly from original date
+- =.+1d= - Repeat daily from completion
+- =++1w= - Repeat weekly from scheduled date
+
+*** Per-Event Notification Times
+
+Override global notification times for specific events:
+
+#+BEGIN_SRC org
+,* IMPORTANT Board Meeting
+SCHEDULED: <2025-10-25 Sat 14:00>
+:PROPERTIES:
+:CHIME_NOTIFY_BEFORE: 30 15 5 0
+:END:
+#+END_SRC
+
+This event will notify at: 30min, 15min, 5min before, and at event time.
+
+** Known Limitations
+
+*** Sexp Diary Entries Not Supported
+
+This format is *not supported*:
+
+#+BEGIN_SRC org
+,* TODO Daily Standup
+SCHEDULED: <%%(memq (calendar-day-of-week date) '(1 2 3 4 5))>
+#+END_SRC
+
+*Workaround:* Use standard repeating timestamps instead:
+
+#+BEGIN_SRC org
+,* TODO Daily Standup
+SCHEDULED: <2025-10-24 Fri 09:00 +1d>
+#+END_SRC
+
+For Monday-Friday events, you can either:
+1. Accept weekend notifications (mark as DONE on weekends)
+2. Create 5 separate entries, one for each weekday with =+1w= repeater
+
+** Full Example Configuration
+
+#+BEGIN_SRC elisp
+ (use-package chime
+ :vc (:url "https://github.com/cjennings/chime.el" :rev :newest)
+ :after (alert org-agenda)
+ :commands (chime-mode chime-check)
+ :config
+ ;; Notification times: 5 minutes before and at event time
+ (setq chime-alert-time '(5 0))
+
+ ;; Chime sound
+ (setq chime-play-sound t)
+ ;; Uses bundled chime.wav by default
+
+ ;; Modeline display
+ (setq chime-modeline-lookahead 120) ;; notify for events 2 hrs ahead
+ (setq chime-modeline-format " ⏰ %s")
+
+ ;; Notification settings
+ (setq chime-notification-title "Reminder")
+ (setq chime-alert-severity 'medium)
+
+ ;; Don't filter by TODO keywords - notify for all events
+ (setq chime-keyword-whitelist nil)
+ (setq chime-keyword-blacklist nil)
+
+ ;; Only notify for non-done items
+ (setq chime-predicate-blacklist
+ '(chime-done-keywords-predicate))
+
+ ;; Enable chime-mode automatically
+ (chime-mode 1))
+#+END_SRC
+
+** Manual Check
+
+You can manually trigger a notification check:
+
+#+BEGIN_SRC elisp
+M-x chime-check
+#+END_SRC
+
+** Troubleshooting
+
+*** No notifications appearing
+
+1. Verify chime-mode is enabled: =M-: chime-mode=
+2. Check that alert is configured correctly:
+ #+BEGIN_SRC elisp
+ (setq alert-default-style 'libnotify) ; or 'notifications on some systems
+ #+END_SRC
+3. Manually test: =M-x chime-check=
+4. Check =*Messages*= buffer for error messages
+
+*** No sound playing
+
+1. Verify sound is enabled: =M-: chime-play-sound= should return =t=
+2. Check sound file exists: =M-: (file-exists-p chime-sound-file)=
+3. Test sound directly: =M-: (play-sound-file chime-sound-file)=
+4. Ensure your system has audio support configured
+
+*** Events not being detected
+
+1. Ensure files are in =org-agenda-files=
+2. Verify timestamps have time components: =<2025-10-25 Sat 14:00>= not =<2025-10-25 Sat>=
+3. Check filtering settings (keyword/tag whitelist/blacklist)
+
+** Requirements
+
+- Emacs 26.1+
+- Org-mode 9.0+
+- =alert= package
+- =dash= package
+- =async= package
+
+** License
+
+GPL-3.0
+
+** Credits
+
+All credit and thanks should go to Artem Khramov for his work on [[https://github.com/akhramov/org-wild-notifier.el][org-wild-notifier]]. Early in 2025, I needed an event notifier in Emacs and found this package. Sadly, the author deprecated org-wild-notifier on Aug 2, 2025 in favor of [[https://github.com/spegoraro/org-alert][org-alert]]. I began fixing bugs and enhancing the feature set into what I needed, then decided it had become different enough to name it CHIME. I plan to maintain this in appreciation and gratitude of Artem's work, and for the larger Emacs community.
+
+** Migration from Org-Wild-Notifier
+
+If you're migrating from org-wild-notifier, you'll need to update your configuration:
+
+1. Change package name:
+ - =(require 'org-wild-notifier)= → =(require 'chime)=
+
+2. Update all configured variable names:
+ - =org-wild-notifier-*= → =chime-*=
+
+3. Update configured function names:
+ - =org-wild-notifier-mode= → =chime-mode=
+ - =org-wild-notifier-check= → =chime-check=
+
+4. Update property names in your org files:
+ - =:WILD_NOTIFIER_NOTIFY_BEFORE:= → =:CHIME_NOTIFY_BEFORE:=
+
diff --git a/chime.el b/chime.el
new file mode 100644
index 0000000..38f4298
--- /dev/null
+++ b/chime.el
@@ -0,0 +1,720 @@
+;;; chime.el --- CHIME Heralds Imminent Events -*- lexical-binding: t -*-
+
+;; Copyright (C) 2017 Artem Khramov
+;; Copyright (C) 2024 Craig Jennings
+
+;; Current Author/Maintainer: Craig Jennings <c@cjennings.net>
+;; Original Author: Artem Khramov <akhramov+emacs@pm.me>
+;; Created: 6 Jan 2017
+;; Version: 0.6.0
+;; Package-Requires: ((alert "1.2") (async "1.9.3") (dash "2.18.0") (emacs "26.1"))
+;; Keywords: notification alert org org-agenda agenda calendar chime sound
+;; URL: https://github.com/cjennings/chime.el
+
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; CHIME (CHIME Heralds Imminent Events) - Customizable org-agenda notifications
+;;
+;; This package provides visual and audible notifications for upcoming org-agenda
+;; events with modeline display of the next upcoming event.
+;;
+;; Features:
+;; - Visual notifications with customizable alert times
+;; - Audible chime sound when notifications appear
+;; - Modeline display of next upcoming event
+;; - Support for SCHEDULED, DEADLINE, and plain timestamps
+;; - Repeating timestamp support (+1w, .+1d, ++1w)
+;; - Per-event notification customization
+;; - Async background checking (runs every minute)
+;;
+;; Quick Start:
+;; (require 'chime)
+;; (setq chime-alert-time '(5 0)) ; 5 min before and at event time
+;; (chime-mode 1)
+;;
+;; Manual check: M-x chime-check
+;;
+;; Notification times can be customized globally via `chime-alert-time'
+;; or per-event using the `CHIME_NOTIFY_BEFORE` property.
+;;
+;; Filter notifications using `chime-keyword-whitelist' and
+;; `chime-keyword-blacklist' variables.
+;;
+;; See README.org for complete documentation.
+
+;;; Code:
+
+(require 'dash)
+(require 'alert)
+(require 'async)
+(require 'org-agenda)
+(require 'org-duration)
+(require 'cl-lib)
+
+(defgroup chime nil
+ "Chime customization options."
+ :group 'org)
+
+(defcustom chime-alert-time '(10)
+ "Time in minutes to get a notification about upcoming event.
+Can be a single integer or a list of integers. Each value represents
+minutes before the event. Use 0 to notify at event time. Cannot be
+negative."
+ :package-version '(chime . "0.1.0")
+ :group 'chime
+ :type '(choice (integer :tag "Notify once")
+ (repeat integer))
+ :set (lambda (symbol value)
+ (let ((values (if (listp value) value (list value))))
+ (dolist (v values)
+ (unless (integerp v)
+ (user-error "Alert time must be an integer, got: %S" v))
+ (when (< v 0)
+ (user-error "Alert time cannot be negative, got: %d" v)))
+ (set-default symbol value))))
+
+(defcustom chime-alert-times-property "CHIME_NOTIFY_BEFORE"
+ "Property name for per-event notification times.
+Use this property in your agenda files to add additional
+notifications to an event."
+ :package-version '(chime . "0.1.0")
+ :group 'chime
+ :type 'string)
+
+(defcustom chime-notification-title "Agenda"
+ "Notifications title."
+ :package-version '(chime . "0.1.0")
+ :group 'chime
+ :type 'string)
+
+(defcustom chime-notification-icon nil
+ "Path to notification icon file."
+ :package-version '(chime . "0.4.1")
+ :group 'chime
+ :type 'string)
+
+(defcustom chime-keyword-whitelist nil
+ "Receive notifications for these keywords only.
+Leave this variable blank if you do not want to filter anything."
+ :package-version '(chime . "0.2.2")
+ :group 'chime
+ :type '(repeat string))
+
+(defcustom chime-keyword-blacklist nil
+ "Never receive notifications for these keywords."
+ :package-version '(chime . "0.2.2")
+ :group 'chime
+ :type '(repeat string))
+
+(defcustom chime-tags-whitelist nil
+ "Receive notifications for these tags only.
+Leave this variable blank if you do not want to filter anything."
+ :package-version '(chime . "0.3.1")
+ :group 'chime
+ :type '(repeat string))
+
+(defcustom chime-tags-blacklist nil
+ "Never receive notifications for these tags."
+ :package-version '(chime . "0.3.1")
+ :group 'chime
+ :type '(repeat string))
+
+(defcustom chime-display-time-format-string "%I:%M %p"
+ "Format string for displaying event times.
+Passed to `format-time-string' when displaying notification times."
+ :package-version '(chime . "0.5.0")
+ :group 'chime
+ :type 'string)
+
+(defcustom chime-predicate-whitelist nil
+ "Receive notifications for events matching these predicates only.
+Each function should take an event POM and return non-nil iff that event should
+trigger a notification. Leave this variable blank if you do not want to filter
+anything."
+ :package-version '(chime . "0.5.0")
+ :group 'chime
+ :type '(function))
+
+(defcustom chime-additional-environment-regexes nil
+ "Additional regular expressions for async environment injection.
+These regexes are provided to `async-inject-environment' before
+running the async command to check notifications."
+ :package-version '(chime . "0.5.0")
+ :group 'chime
+ :type '(string))
+
+(defcustom chime-predicate-blacklist
+ '(chime-done-keywords-predicate)
+ "Never receive notifications for events matching these predicates.
+Each function should take an event POM and return non-nil iff that event should
+not trigger a notification."
+ :package-version '(chime . "0.5.0")
+ :group 'chime
+ :type '(function))
+
+(defcustom chime-alert-severity 'medium
+ "Severity of the alert.
+Options: \\='high \\='medium \\='low"
+ :package-version '(chime . "0.3.1")
+ :group 'chime
+ :type 'symbol
+ :options '(high medium low))
+
+(defcustom chime-extra-alert-plist nil
+ "Additional arguments that should be passed to invocations of `alert'."
+ :package-version "v0.5.0"
+ :group 'chime
+ :type 'plist)
+
+(defcustom chime-day-wide-alert-times nil
+ "List of time strings for day-wide event alerts.
+Each string specifies a time of day when day-wide events should trigger."
+ :package-version '(chime . "0.5.0")
+ :group 'chime
+ :type 'string)
+
+(defcustom chime-show-any-overdue-with-day-wide-alerts t
+ "Show any overdue TODO items along with day wide alerts whenever they are shown."
+ :package-version '(chime . "0.5.0")
+ :group 'chime
+ :type 'string)
+
+(defcustom chime-modeline-lookahead 30
+ "Minutes ahead to look for next event to display in modeline.
+Should be larger than notification alert times for advance awareness.
+Set to 0 to disable modeline display."
+ :package-version '(chime . "0.5.1")
+ :group 'chime
+ :type 'integer)
+
+(defcustom chime-modeline-format " ⏰ %s"
+ "Format string for modeline display.
+%s will be replaced with the event description (time and title)."
+ :package-version '(chime . "0.5.1")
+ :group 'chime
+ :type 'string)
+
+(defcustom chime-play-sound t
+ "Whether to play a sound when notifications are displayed.
+When non-nil, plays the sound file specified in `chime-sound-file'."
+ :package-version '(chime . "0.6.0")
+ :group 'chime
+ :type 'boolean)
+
+(defcustom chime-sound-file
+ (expand-file-name "sounds/chime.wav"
+ (file-name-directory (or load-file-name buffer-file-name)))
+ "Path to sound file to play when notifications are displayed.
+Defaults to the bundled chime.wav file.
+Set to nil to use Emacs default beep instead.
+Should be an absolute path to a .wav, .au, or other sound file
+supported by your system."
+ :package-version '(chime . "0.6.0")
+ :group 'chime
+ :type '(choice (const :tag "Use system beep" nil)
+ (file :tag "Sound file path")))
+
+(defvar chime--timer nil
+ "Timer value.")
+
+(defvar chime--process nil
+ "Currently-running async process.")
+
+(defvar chime--agenda-buffer-name "*org wild notifier affairs*"
+ "Name for temporary \\='org-agenda\\=' buffer.")
+
+(defvar chime--last-check-time (seconds-to-time 0)
+ "Last time checked for events.")
+
+(defvar chime--next-event nil
+ "Next upcoming event for modeline display.
+Stored as (EVENT-MSG . MINUTES-UNTIL) or nil if no upcoming event.")
+
+(defvar chime-modeline-string nil
+ "Modeline string showing next upcoming event.")
+;;;###autoload(put 'chime-modeline-string 'risky-local-variable t)
+(put 'chime-modeline-string 'risky-local-variable t)
+
+(defun chime--time= (&rest list)
+ "Compare timestamps.
+Comparison is performed by converted each element of LIST onto string
+in order to ignore seconds."
+ (->> list
+ (--map (format-time-string "%d:%H:%M" it))
+ (-uniq)
+ (length)
+ (= 1)))
+
+(defun chime--today ()
+ "Get the timestamp for the beginning of current day."
+ (apply 'encode-time
+ (append '(0 0 0) (nthcdr 3 (decode-time (current-time))))))
+
+(defun chime--timestamp-within-interval-p (timestamp interval)
+ "Check whether TIMESTAMP is within notification INTERVAL.
+Returns non-nil if TIMESTAMP matches current time plus INTERVAL minutes.
+Returns nil if TIMESTAMP or INTERVAL is invalid."
+ (and timestamp
+ interval
+ (numberp interval)
+ ;; Validate timestamp is a proper time value (list of integers)
+ (listp timestamp)
+ (chime--time=
+ (time-add (current-time) (seconds-to-time (* 60 interval)))
+ timestamp)))
+
+(defun chime--notifications (event)
+ "Get notifications for given EVENT.
+Returns a list of time information interval pairs."
+ (->> (list
+ (chime--filter-day-wide-events (cadr (assoc 'times event)))
+ (cdr (assoc 'intervals event)))
+ (apply '-table-flat (lambda (ts int) (list ts int)))
+ ;; When no values are provided for table flat, we get the second values
+ ;; paired with nil.
+ (--filter (not (null (car it))))
+ (--filter (chime--timestamp-within-interval-p (cdar it) (cadr it)))))
+
+(defun chime--has-timestamp (s)
+ "Check if S contain a timestamp with a time component.
+Returns non-nil only if the timestamp includes HH:MM time information."
+ (and s
+ (stringp s)
+ (string-match org-ts-regexp0 s)
+ (match-beginning 7)))
+
+(defun chime--filter-day-wide-events (times)
+ "Filter TIMES list to include only events with timestamps."
+ (--filter (chime--has-timestamp (car it)) times))
+
+(defun chime--time-left (seconds)
+ "Human-friendly representation for SECONDS."
+ (-> seconds
+ (pcase
+ ((pred (>= 0)) "right now")
+ ((pred (>= 3600)) "in %M")
+ (_ "in %H %M"))
+
+ (format-seconds seconds)))
+
+(defun chime--get-hh-mm-from-org-time-string (time-string)
+ "Convert given org time-string TIME-STRING into string with \\='hh:mm\\=' format."
+ (format-time-string
+ chime-display-time-format-string
+ (encode-time (org-parse-time-string time-string))))
+
+(defun chime--notification-text (str-interval event)
+ "For given STR-INTERVAL list and EVENT get notification wording."
+ (format "%s at %s (%s)"
+ (cdr (assoc 'title event))
+ (chime--get-hh-mm-from-org-time-string (car str-interval))
+ (chime--time-left (* 60 (cdr str-interval)))))
+
+(defun chime-get-minutes-into-day (time)
+ "Get minutes elapsed since midnight for TIME string."
+ (org-duration-to-minutes (org-get-time-of-day time t)))
+
+(defun chime-get-hours-minutes-from-time (time-string)
+ "Extract hours and minutes from TIME-STRING.
+Returns a list of (HOURS MINUTES)."
+ (let ((total-minutes (truncate (chime-get-minutes-into-day time-string))))
+ (list (/ total-minutes 60)
+ (mod total-minutes 60))))
+
+(defun chime-set-hours-minutes-for-time (time hours minutes)
+ "Set HOURS and MINUTES for TIME, preserving date components."
+ (cl-destructuring-bind (_s _m _h day month year dow dst utcoff) (decode-time time)
+ (encode-time 0 minutes hours day month year dow dst utcoff)))
+
+(defun chime-current-time-matches-time-of-day-string (time-of-day-string)
+ "Check if current time matches TIME-OF-DAY-STRING."
+ (let ((now (current-time)))
+ (chime--time=
+ now
+ (apply 'chime-set-hours-minutes-for-time
+ now
+ (chime-get-hours-minutes-from-time time-of-day-string)))))
+
+(defun chime-current-time-is-day-wide-time ()
+ "Check if current time matches any day-wide alert time."
+ (--any (chime-current-time-matches-time-of-day-string it)
+ chime-day-wide-alert-times))
+
+(defun chime-day-wide-notifications (events)
+ "Generate notification texts for day-wide EVENTS."
+ (->> events
+ (-filter 'chime-display-as-day-wide-event)
+ (-map 'chime--day-wide-notification-text)
+ (-uniq)))
+
+(defun chime-display-as-day-wide-event (event)
+ "Check if EVENT should be displayed as a day-wide event.
+`chime-event-has-any-passed-time' is a requirement regardless of
+whether `chime-show-any-overdue-with-day-wide-alerts' is set,
+because the events list can include events scheduled tomorrow.
+We only want to alert for things scheduled today."
+ (and (chime-event-has-any-passed-time event)
+ (or chime-show-any-overdue-with-day-wide-alerts
+ (chime-event-has-any-day-wide-timestamp event))))
+
+(defun chime-event-has-any-day-wide-timestamp (event)
+ "Check if EVENT has any day-wide (no time component) timestamps."
+ (--any (not (chime--has-timestamp (car it)))
+ (car (cdr (assoc 'times event)))))
+
+(defun chime-event-has-any-passed-time (event)
+ "Check if EVENT has any timestamps in the past."
+ (--any (time-less-p (cdr it) (current-time))
+ (car (cdr (assoc 'times event )))))
+
+(defun chime--day-wide-notification-text (event)
+ "For given STR-INTERVAL list and EVENT get notification wording."
+ (format "%s is due or scheduled today"
+ (cdr (assoc 'title event))))
+
+(defun chime--check-event (event)
+ "Get notifications for given EVENT.
+Returns a list of notification messages"
+ (->> (chime--notifications event)
+ (--map (chime--notification-text `(,(caar it) . ,(cadr it)) event))))
+
+(defun chime--update-modeline (events)
+ "Update modeline with next upcoming event from EVENTS.
+Only shows events within `chime-modeline-lookahead' minutes."
+ (if (or (not chime-modeline-lookahead)
+ (zerop chime-modeline-lookahead))
+ (setq chime-modeline-string nil)
+ (let ((soonest-event nil)
+ (soonest-minutes nil)
+ (now (current-time)))
+ ;; Find soonest event within lookahead window
+ (dolist (event events)
+ (let* ((all-times (cadr (assoc 'times event)))
+ (times (chime--filter-day-wide-events all-times)))
+ (dolist (time-info times)
+ (when-let* ((time-str (car time-info))
+ (event-time (cdr time-info))
+ ;; Calculate minutes until event
+ (seconds-until (- (float-time event-time) (float-time now)))
+ (minutes-until (/ seconds-until 60)))
+ ;; Only consider future events within lookahead window
+ (when (and (> minutes-until 0)
+ (<= minutes-until chime-modeline-lookahead)
+ (or (not soonest-minutes)
+ (< minutes-until soonest-minutes)))
+ (setq soonest-minutes minutes-until)
+ (setq soonest-event
+ (chime--notification-text
+ `(,time-str . ,minutes-until) event)))))))
+ ;; Format and set modeline string
+ (setq chime-modeline-string
+ (when soonest-event
+ (format chime-modeline-format soonest-event)))
+ (force-mode-line-update))))
+
+(defun chime--get-tags (marker)
+ "Retrieve tags of MARKER."
+ (-> (org-entry-get marker "TAGS")
+ (or "")
+ (org-split-string ":")))
+
+(defun chime--whitelist-predicates ()
+ "Return list of whitelist predicate functions.
+Combines keyword, tag, and custom predicate whitelists."
+ (->> `([,chime-keyword-whitelist
+ (lambda (it)
+ (-contains-p chime-keyword-whitelist
+ (org-entry-get it "TODO")))]
+
+ [,chime-tags-whitelist
+ (lambda (it)
+ (-intersection chime-tags-whitelist
+ (chime--get-tags it)))]
+
+ [,chime-predicate-whitelist
+ (lambda (marker)
+ (--some? (funcall it marker) chime-predicate-whitelist))])
+ (--filter (aref it 0))
+ (--map (aref it 1))))
+
+(defun chime--blacklist-predicates ()
+ "Return list of blacklist predicate functions.
+Combines keyword, tag, and custom predicate blacklists."
+ (->> `([,chime-keyword-blacklist
+ (lambda (it)
+ (-contains-p chime-keyword-blacklist
+ (org-entry-get it "TODO")))]
+
+ [,chime-tags-blacklist
+ (lambda (it)
+ (-intersection chime-tags-blacklist
+ (chime--get-tags it)))]
+
+ [,chime-predicate-blacklist
+ (lambda (marker)
+ (--some? (funcall it marker) chime-predicate-blacklist))])
+ (--filter (aref it 0))
+ (--map (aref it 1))))
+
+(defun chime-done-keywords-predicate (marker)
+ "Check if entry at MARKER has a done keyword."
+ (with-current-buffer (marker-buffer marker)
+ (save-excursion
+ (goto-char (marker-position marker))
+ (member (nth 2 (org-heading-components)) org-done-keywords))))
+
+(defun chime--apply-whitelist (markers)
+ "Apply whitelist to MARKERS."
+ (-if-let (whitelist-predicates (chime--whitelist-predicates))
+ (-> (apply '-orfn whitelist-predicates)
+ (-filter markers))
+ markers))
+
+(defun chime--apply-blacklist (markers)
+ "Apply blacklist to MARKERS."
+ (-if-let (blacklist-predicates (chime--blacklist-predicates))
+ (-> (apply '-orfn blacklist-predicates)
+ (-remove markers))
+ markers))
+
+(defconst chime-default-environment-regex
+ (macroexpand
+ `(rx string-start
+ (or ,@(mapcar (lambda (literal) (list 'literal literal))
+ (list
+ "org-agenda-files"
+ "load-path"
+ "org-todo-keywords"
+ "chime-alert-time"
+ "chime-keyword-whitelist"
+ "chime-keyword-blacklist"
+ "chime-tags-whitelist"
+ "chime-tags-blacklist"
+ "chime-predicate-whitelist"
+ "chime-predicate-blacklist")))
+ string-end)))
+
+
+(defun chime-environment-regex ()
+ "Generate regex for environment variables to inject into async process."
+ (macroexpand
+ `(rx (or
+ ,@(mapcar (lambda (regexp) (list 'regexp regexp))
+ (cons chime-default-environment-regex
+ chime-additional-environment-regexes))))))
+
+(defun chime--retrieve-events ()
+ "Get events from agenda view."
+ `(lambda ()
+ (setf org-agenda-use-time-grid nil)
+ (setf org-agenda-compact-blocks t)
+ ,(async-inject-variables (chime-environment-regex))
+
+ (package-initialize)
+ (require 'chime)
+
+ (org-agenda-list 2 (org-read-date nil nil "today"))
+
+ (->> (org-split-string (buffer-string) "\n")
+ (--map (plist-get
+ (org-fix-agenda-info (text-properties-at 0 it))
+ 'org-marker))
+ (-non-nil)
+ (chime--apply-whitelist)
+ (chime--apply-blacklist)
+ (-map 'chime--gather-info))))
+
+(defun chime--notify (event-msg)
+ "Notify about an event using `alert' library.
+EVENT-MSG is a string representation of the event."
+ ;; Play sound if enabled
+ (when chime-play-sound
+ (condition-case err
+ (if chime-sound-file
+ (when (file-exists-p chime-sound-file)
+ (play-sound-file chime-sound-file))
+ ;; Use default Emacs bell/beep if no file specified
+ (beep))
+ (error
+ (message "chime: Failed to play sound: %s"
+ (error-message-string err)))))
+ ;; Show visual notification
+ (apply
+ 'alert event-msg
+ :icon chime-notification-icon
+ :title chime-notification-title
+ :severity chime-alert-severity
+ :category 'chime
+ chime-extra-alert-plist))
+
+(defun chime--timestamp-parse (timestamp)
+ "Parse TIMESTAMP and return time in list-of-integer format.
+Returns nil if parsing fails or timestamp is malformed."
+ (condition-case err
+ (when (and timestamp
+ (stringp timestamp)
+ (not (string-empty-p timestamp))
+ ;; Validate angle bracket format
+ (string-match-p "<.*>" timestamp)
+ ;; Ensure timestamp has time component (HH:MM format)
+ (string-match-p "[0-9]\\{1,2\\}:[0-9]\\{2\\}" timestamp))
+ (let ((parsed (org-parse-time-string timestamp))
+ (today (format-time-string "<%Y-%m-%d>")))
+ (when (and parsed
+ (decoded-time-hour parsed)
+ (decoded-time-minute parsed))
+ ;; Validate date components are in reasonable ranges
+ (let ((month (decoded-time-month parsed))
+ (day (decoded-time-day parsed))
+ (hour (decoded-time-hour parsed))
+ (minute (decoded-time-minute parsed)))
+ (when (and month day hour minute
+ (>= month 1) (<= month 12)
+ (>= day 1) (<= day 31)
+ (>= hour 0) (<= hour 23)
+ (>= minute 0) (<= minute 59))
+ ;; seconds-to-time returns also milliseconds and nanoseconds so we
+ ;; have to "trim" the list
+ (butlast
+ (seconds-to-time
+ (time-add
+ ;; we get the cycled absolute day (not hour and minutes)
+ (org-time-from-absolute (org-closest-date timestamp today 'past))
+ ;; so we have to add the minutes too
+ (+ (* hour 3600)
+ (* minute 60))))
+ 2))))))
+ (error
+ (message "chime: Failed to parse timestamp '%s': %s"
+ timestamp (error-message-string err))
+ nil)))
+
+(defun chime--extract-time (marker)
+ "Extract timestamps from MARKER.
+Timestamps are extracted as cons cells. car holds org-formatted
+string, cdr holds time in list-of-integer format."
+ (-non-nil
+ (--map
+ (let ((org-timestamp (org-entry-get marker it)))
+ (and org-timestamp
+ (cons org-timestamp
+ (chime--timestamp-parse org-timestamp))))
+ '("DEADLINE" "SCHEDULED" "TIMESTAMP"))))
+
+(defun chime--extract-title (marker)
+ "Extract event title from MARKER.
+MARKER acts like the event's identifier."
+ (org-with-point-at marker
+ (-let (((_lvl _reduced-lvl _todo _priority title _tags)
+ (org-heading-components)))
+ title)))
+
+(defun chime--extract-notication-intervals (marker)
+ "Extract notification intervals from the event's properties.
+MARKER acts like the event's identifier. Resulting list also contains
+standard notification interval (`chime-alert-time')."
+ `(,@(-flatten (list chime-alert-time))
+ ,@(-map 'string-to-number
+ (org-entry-get-multivalued-property
+ marker
+ chime-alert-times-property))))
+
+(defun chime--gather-info (marker)
+ "Collect information about an event.
+MARKER acts like event's identifier."
+ `((times . (,(chime--extract-time marker)))
+ (title . ,(chime--extract-title marker))
+ (intervals . ,(chime--extract-notication-intervals marker))))
+
+(defun chime--stop ()
+ "Stop the notification timer and cancel any in-progress check."
+ (-some-> chime--timer (cancel-timer))
+ (when chime--process
+ (interrupt-process chime--process)
+ (setq chime--process nil)))
+
+(defun chime--start ()
+ "Start the notification timer. Cancel old one, if any.
+Timer is scheduled on the beginning of every minute, so for
+smoother experience this function also runs a check without timer."
+ (chime--stop)
+ (chime-check)
+
+ (--> (format-time-string "%H:%M" (time-add (current-time) 60))
+ (run-at-time it 60 'chime-check)
+ (setf chime--timer it)))
+
+(defun chime--check-events (events)
+ "Process EVENTS and send notifications for upcoming items.
+Clears the async process flag, sends notifications for matching
+events, handles day-wide alerts, and updates the modeline."
+ (setq chime--process nil)
+ ;; Handle notifications
+ (-each
+ (->> events
+ (-map 'chime--check-event)
+ (-flatten)
+ (-uniq))
+ 'chime--notify)
+ (when (chime-current-time-is-day-wide-time)
+ (mapc 'chime--notify
+ (chime-day-wide-notifications events)))
+ ;; Update modeline with next upcoming event
+ (chime--update-modeline events)
+ (setq chime--last-check-time (current-time)))
+
+;;;###autoload
+(defun chime-check ()
+ "Parse agenda view and notify about upcoming events.
+
+Do nothing if a check is already in progress in the background."
+ (interactive)
+ (unless (and chime--process
+ (process-live-p chime--process))
+ (setq chime--process
+ (let ((default-directory user-emacs-directory)
+ (async-prompt-for-password nil)
+ (async-process-noquery-on-exit t))
+ (async-start
+ (chime--retrieve-events)
+ 'chime--check-events)))))
+
+;;;###autoload
+(define-minor-mode chime-mode
+ "Toggle org notifications globally.
+When enabled parses your agenda once a minute and emits notifications
+if needed."
+ :global
+ :lighter "Chime"
+ (if chime-mode
+ (progn
+ (chime--start)
+ ;; Add modeline string to global-mode-string
+ (when (> chime-modeline-lookahead 0)
+ (if global-mode-string
+ (add-to-list 'global-mode-string 'chime-modeline-string 'append)
+ (setq global-mode-string '("" chime-modeline-string)))))
+ (progn
+ (chime--stop)
+ ;; Remove modeline string from global-mode-string
+ (setq global-mode-string
+ (delq 'chime-modeline-string global-mode-string))
+ (setq chime-modeline-string nil)
+ (force-mode-line-update))))
+
+(provide 'chime)
+
+;;; chime.el ends here
diff --git a/sounds/chime.wav b/sounds/chime.wav
new file mode 100644
index 0000000..5b9f3ca
--- /dev/null
+++ b/sounds/chime.wav
Binary files differ
diff --git a/tests/test-chime-apply-blacklist.el b/tests/test-chime-apply-blacklist.el
new file mode 100644
index 0000000..6f785ef
--- /dev/null
+++ b/tests/test-chime-apply-blacklist.el
@@ -0,0 +1,292 @@
+;;; test-chime-apply-blacklist.el --- Tests for chime--apply-blacklist -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2024 Craig Jennings
+
+;; Author: Craig Jennings <c@cjennings.net>
+
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Unit tests for chime--apply-blacklist function.
+;; Tests cover normal cases, boundary cases, and error cases.
+
+;;; Code:
+
+;; Initialize package system for batch mode
+(when noninteractive
+ (package-initialize))
+
+(require 'ert)
+
+;; Load dependencies required by chime
+(require 'dash)
+(require 'alert)
+(require 'async)
+(require 'org-agenda)
+
+;; Load chime from parent directory
+(load (expand-file-name "../chime.el") nil t)
+
+;; Load test utilities
+(require 'testutil-general (expand-file-name "testutil-general.el"))
+
+;;; Setup and Teardown
+
+(defun test-chime-apply-blacklist-setup ()
+ "Setup function run before each test."
+ (chime-create-test-base-dir)
+ ;; Reset blacklist settings
+ (setq chime-keyword-blacklist nil)
+ (setq chime-tags-blacklist nil)
+ (setq chime-predicate-blacklist nil))
+
+(defun test-chime-apply-blacklist-teardown ()
+ "Teardown function run after each test."
+ (chime-delete-test-base-dir)
+ (setq chime-keyword-blacklist nil)
+ (setq chime-tags-blacklist nil)
+ (setq chime-predicate-blacklist nil))
+
+;;; Normal Cases
+
+(ert-deftest test-chime-apply-blacklist-nil-blacklist-returns-all-markers ()
+ "Test that nil blacklist returns all markers unchanged."
+ (test-chime-apply-blacklist-setup)
+ (unwind-protect
+ (let* ((chime-keyword-blacklist nil)
+ (chime-tags-blacklist nil)
+ (markers (list (make-marker) (make-marker) (make-marker)))
+ (result (chime--apply-blacklist markers)))
+ ;; Should return all markers when blacklist is nil
+ (should (equal (length result) 3)))
+ (test-chime-apply-blacklist-teardown)))
+
+(ert-deftest test-chime-apply-blacklist-keyword-blacklist-filters-correctly ()
+ "Test that keyword blacklist filters out markers correctly."
+ (test-chime-apply-blacklist-setup)
+ (unwind-protect
+ (with-temp-buffer
+ (org-mode)
+ (insert "* TODO Task 1\n")
+ (let ((marker1 (copy-marker (point))))
+ (insert "* DONE Task 2\n")
+ (let ((marker2 (copy-marker (point))))
+ (insert "* TODO Task 3\n")
+ (let ((marker3 (copy-marker (point)))
+ (chime-keyword-blacklist '("DONE")))
+ ;; Mock org-entry-get to return appropriate keywords
+ (cl-letf (((symbol-function 'org-entry-get)
+ (lambda (pom property &optional inherit literal-nil)
+ (when (equal property "TODO")
+ (cond
+ ((equal pom marker1) "TODO")
+ ((equal pom marker2) "DONE")
+ ((equal pom marker3) "TODO")
+ (t nil))))))
+ (let ((result (chime--apply-blacklist (list marker1 marker2 marker3))))
+ ;; Should filter out DONE marker
+ (should (= (length result) 2))
+ (should (member marker1 result))
+ (should-not (member marker2 result))
+ (should (member marker3 result))))))))
+ (test-chime-apply-blacklist-teardown)))
+
+(ert-deftest test-chime-apply-blacklist-tags-blacklist-filters-correctly ()
+ "Test that tags blacklist filters out markers correctly."
+ (test-chime-apply-blacklist-setup)
+ (unwind-protect
+ (with-temp-buffer
+ (org-mode)
+ (insert "* Task 1\n")
+ (let ((marker1 (copy-marker (point))))
+ (insert "* Task 2\n")
+ (let ((marker2 (copy-marker (point))))
+ (insert "* Task 3\n")
+ (let ((marker3 (copy-marker (point)))
+ (chime-tags-blacklist '("personal")))
+ ;; Mock chime--get-tags to return appropriate tags
+ (cl-letf (((symbol-function 'chime--get-tags)
+ (lambda (pom)
+ (cond
+ ((equal pom marker1) '("work" "urgent"))
+ ((equal pom marker2) '("personal"))
+ ((equal pom marker3) '("work"))
+ (t nil)))))
+ (let ((result (chime--apply-blacklist (list marker1 marker2 marker3))))
+ ;; Should filter out marker with "personal" tag
+ (should (= (length result) 2))
+ (should (member marker1 result))
+ (should-not (member marker2 result))
+ (should (member marker3 result))))))))
+ (test-chime-apply-blacklist-teardown)))
+
+(ert-deftest test-chime-apply-blacklist-keyword-and-tags-blacklist-uses-or-logic ()
+ "Test that both keyword and tags blacklists use OR logic."
+ (test-chime-apply-blacklist-setup)
+ (unwind-protect
+ (with-temp-buffer
+ (org-mode)
+ (insert "* TODO Task 1\n")
+ (let ((marker1 (copy-marker (point))))
+ (insert "* DONE Task 2\n")
+ (let ((marker2 (copy-marker (point))))
+ (insert "* NEXT Task 3\n")
+ (let ((marker3 (copy-marker (point)))
+ (chime-keyword-blacklist '("DONE"))
+ (chime-tags-blacklist '("archive")))
+ ;; Mock functions
+ (cl-letf (((symbol-function 'org-entry-get)
+ (lambda (pom property &optional inherit literal-nil)
+ (when (equal property "TODO")
+ (cond
+ ((equal pom marker1) "TODO")
+ ((equal pom marker2) "DONE")
+ ((equal pom marker3) "NEXT")
+ (t nil)))))
+ ((symbol-function 'chime--get-tags)
+ (lambda (pom)
+ (cond
+ ((equal pom marker1) nil)
+ ((equal pom marker2) nil)
+ ((equal pom marker3) '("archive"))
+ (t nil)))))
+ (let ((result (chime--apply-blacklist (list marker1 marker2 marker3))))
+ ;; Should filter out marker2 (DONE) and marker3 (archive tag)
+ (should (= (length result) 1))
+ (should (member marker1 result))
+ (should-not (member marker2 result))
+ (should-not (member marker3 result))))))))
+ (test-chime-apply-blacklist-teardown)))
+
+(ert-deftest test-chime-apply-blacklist-multiple-keywords-filters-all ()
+ "Test that multiple keywords in blacklist filters all matching."
+ (test-chime-apply-blacklist-setup)
+ (unwind-protect
+ (with-temp-buffer
+ (org-mode)
+ (insert "* TODO Task 1\n")
+ (let ((marker1 (copy-marker (point))))
+ (insert "* DONE Task 2\n")
+ (let ((marker2 (copy-marker (point))))
+ (insert "* CANCELLED Task 3\n")
+ (let ((marker3 (copy-marker (point)))
+ (chime-keyword-blacklist '("DONE" "CANCELLED")))
+ (cl-letf (((symbol-function 'org-entry-get)
+ (lambda (pom property &optional inherit literal-nil)
+ (when (equal property "TODO")
+ (cond
+ ((equal pom marker1) "TODO")
+ ((equal pom marker2) "DONE")
+ ((equal pom marker3) "CANCELLED")
+ (t nil))))))
+ (let ((result (chime--apply-blacklist (list marker1 marker2 marker3))))
+ ;; Should only keep TODO marker
+ (should (= (length result) 1))
+ (should (member marker1 result))))))))
+ (test-chime-apply-blacklist-teardown)))
+
+;;; Boundary Cases
+
+(ert-deftest test-chime-apply-blacklist-empty-markers-list-returns-empty ()
+ "Test that empty markers list returns empty."
+ (test-chime-apply-blacklist-setup)
+ (unwind-protect
+ (let ((chime-keyword-blacklist '("DONE"))
+ (result (chime--apply-blacklist '())))
+ (should (equal result '())))
+ (test-chime-apply-blacklist-teardown)))
+
+(ert-deftest test-chime-apply-blacklist-single-item-blacklist-works ()
+ "Test that single-item blacklist works correctly."
+ (test-chime-apply-blacklist-setup)
+ (unwind-protect
+ (with-temp-buffer
+ (org-mode)
+ (insert "* TODO Task 1\n")
+ (let ((marker1 (copy-marker (point))))
+ (insert "* DONE Task 2\n")
+ (let ((marker2 (copy-marker (point)))
+ (chime-keyword-blacklist '("DONE")))
+ (cl-letf (((symbol-function 'org-entry-get)
+ (lambda (pom property &optional inherit literal-nil)
+ (when (equal property "TODO")
+ (cond
+ ((equal pom marker1) "TODO")
+ ((equal pom marker2) "DONE")
+ (t nil))))))
+ (let ((result (chime--apply-blacklist (list marker1 marker2))))
+ (should (= (length result) 1))
+ (should (member marker1 result)))))))
+ (test-chime-apply-blacklist-teardown)))
+
+(ert-deftest test-chime-apply-blacklist-all-markers-blacklisted-returns-empty ()
+ "Test that blacklisting all markers returns empty list."
+ (test-chime-apply-blacklist-setup)
+ (unwind-protect
+ (with-temp-buffer
+ (org-mode)
+ (insert "* DONE Task 1\n")
+ (let ((marker1 (copy-marker (point))))
+ (insert "* DONE Task 2\n")
+ (let ((marker2 (copy-marker (point)))
+ (chime-keyword-blacklist '("DONE")))
+ (cl-letf (((symbol-function 'org-entry-get)
+ (lambda (pom property &optional inherit literal-nil)
+ (when (equal property "TODO")
+ (cond
+ ((equal pom marker1) "DONE")
+ ((equal pom marker2) "DONE")
+ (t nil))))))
+ (let ((result (chime--apply-blacklist (list marker1 marker2))))
+ (should (equal result '())))))))
+ (test-chime-apply-blacklist-teardown)))
+
+;;; Error Cases
+
+(ert-deftest test-chime-apply-blacklist-handles-nil-keyword-gracefully ()
+ "Test that nil keyword in marker is handled gracefully."
+ (test-chime-apply-blacklist-setup)
+ (unwind-protect
+ (with-temp-buffer
+ (org-mode)
+ (insert "* Entry without TODO keyword\n")
+ (let ((marker1 (copy-marker (point)))
+ (chime-keyword-blacklist '("DONE")))
+ (cl-letf (((symbol-function 'org-entry-get)
+ (lambda (pom property &optional inherit literal-nil)
+ nil)))
+ (let ((result (chime--apply-blacklist (list marker1))))
+ ;; Should keep marker with nil keyword (not in blacklist)
+ (should (= (length result) 1))))))
+ (test-chime-apply-blacklist-teardown)))
+
+(ert-deftest test-chime-apply-blacklist-handles-nil-tags-gracefully ()
+ "Test that nil tags in marker is handled gracefully."
+ (test-chime-apply-blacklist-setup)
+ (unwind-protect
+ (with-temp-buffer
+ (org-mode)
+ (insert "* Entry without tags\n")
+ (let ((marker1 (copy-marker (point)))
+ (chime-tags-blacklist '("archive")))
+ (cl-letf (((symbol-function 'chime--get-tags)
+ (lambda (pom) nil)))
+ (let ((result (chime--apply-blacklist (list marker1))))
+ ;; Should keep marker with nil tags (not in blacklist)
+ (should (= (length result) 1))))))
+ (test-chime-apply-blacklist-teardown)))
+
+(provide 'test-chime-apply-blacklist)
+;;; test-chime-apply-blacklist.el ends here
diff --git a/tests/test-chime-apply-whitelist.el b/tests/test-chime-apply-whitelist.el
new file mode 100644
index 0000000..d89f1b5
--- /dev/null
+++ b/tests/test-chime-apply-whitelist.el
@@ -0,0 +1,283 @@
+;;; test-chime-apply-whitelist.el --- Tests for chime--apply-whitelist -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2024 Craig Jennings
+
+;; Author: Craig Jennings <c@cjennings.net>
+
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Unit tests for chime--apply-whitelist function.
+;; Tests cover normal cases, boundary cases, and error cases.
+
+;;; Code:
+
+;; Initialize package system for batch mode
+(when noninteractive
+ (package-initialize))
+
+(require 'ert)
+
+;; Load dependencies required by chime
+(require 'dash)
+(require 'alert)
+(require 'async)
+(require 'org-agenda)
+
+;; Load chime from parent directory
+(load (expand-file-name "../chime.el") nil t)
+
+;; Load test utilities
+(require 'testutil-general (expand-file-name "testutil-general.el"))
+
+;;; Setup and Teardown
+
+(defun test-chime-apply-whitelist-setup ()
+ "Setup function run before each test."
+ (chime-create-test-base-dir)
+ ;; Reset whitelist settings
+ (setq chime-keyword-whitelist nil)
+ (setq chime-tags-whitelist nil)
+ (setq chime-predicate-whitelist nil))
+
+(defun test-chime-apply-whitelist-teardown ()
+ "Teardown function run after each test."
+ (chime-delete-test-base-dir)
+ (setq chime-keyword-whitelist nil)
+ (setq chime-tags-whitelist nil)
+ (setq chime-predicate-whitelist nil))
+
+(defun test-chime-create-org-marker (keyword tags)
+ "Create a marker pointing to an org entry with KEYWORD and TAGS.
+Returns a marker with mocked org-entry-get and chime--get-tags."
+ (with-temp-buffer
+ (org-mode)
+ (insert (format "* %s Test Entry\n" (or keyword "")))
+ (let ((marker (point-marker)))
+ ;; Mock org-entry-get to return the keyword
+ (cl-letf (((symbol-function 'org-entry-get)
+ (lambda (pom property &optional inherit literal-nil)
+ (when (and (equal pom marker) (equal property "TODO"))
+ keyword)))
+ ((symbol-function 'chime--get-tags)
+ (lambda (pom)
+ (when (equal pom marker)
+ tags))))
+ marker))))
+
+;;; Normal Cases
+
+(ert-deftest test-chime-apply-whitelist-nil-whitelist-returns-all-markers ()
+ "Test that nil whitelist returns all markers unchanged."
+ (test-chime-apply-whitelist-setup)
+ (unwind-protect
+ (let* ((chime-keyword-whitelist nil)
+ (chime-tags-whitelist nil)
+ (markers (list (make-marker) (make-marker) (make-marker)))
+ (result (chime--apply-whitelist markers)))
+ ;; Should return all markers when whitelist is nil
+ (should (equal (length result) 3)))
+ (test-chime-apply-whitelist-teardown)))
+
+(ert-deftest test-chime-apply-whitelist-keyword-whitelist-filters-correctly ()
+ "Test that keyword whitelist filters markers correctly."
+ (test-chime-apply-whitelist-setup)
+ (unwind-protect
+ (with-temp-buffer
+ (org-mode)
+ (insert "* TODO Task 1\n")
+ (let ((marker1 (copy-marker (point))))
+ (insert "* DONE Task 2\n")
+ (let ((marker2 (copy-marker (point))))
+ (insert "* TODO Task 3\n")
+ (let ((marker3 (copy-marker (point)))
+ (chime-keyword-whitelist '("TODO")))
+ ;; Mock org-entry-get to return appropriate keywords
+ (cl-letf (((symbol-function 'org-entry-get)
+ (lambda (pom property &optional inherit literal-nil)
+ (when (equal property "TODO")
+ (cond
+ ((equal pom marker1) "TODO")
+ ((equal pom marker2) "DONE")
+ ((equal pom marker3) "TODO")
+ (t nil))))))
+ (let ((result (chime--apply-whitelist (list marker1 marker2 marker3))))
+ ;; Should only return TODO markers
+ (should (= (length result) 2))
+ (should (member marker1 result))
+ (should-not (member marker2 result))
+ (should (member marker3 result))))))))
+ (test-chime-apply-whitelist-teardown)))
+
+(ert-deftest test-chime-apply-whitelist-tags-whitelist-filters-correctly ()
+ "Test that tags whitelist filters markers correctly."
+ (test-chime-apply-whitelist-setup)
+ (unwind-protect
+ (with-temp-buffer
+ (org-mode)
+ (insert "* Task 1\n")
+ (let ((marker1 (copy-marker (point))))
+ (insert "* Task 2\n")
+ (let ((marker2 (copy-marker (point))))
+ (insert "* Task 3\n")
+ (let ((marker3 (copy-marker (point)))
+ (chime-tags-whitelist '("work")))
+ ;; Mock chime--get-tags to return appropriate tags
+ (cl-letf (((symbol-function 'chime--get-tags)
+ (lambda (pom)
+ (cond
+ ((equal pom marker1) '("work" "urgent"))
+ ((equal pom marker2) '("personal"))
+ ((equal pom marker3) '("work"))
+ (t nil)))))
+ (let ((result (chime--apply-whitelist (list marker1 marker2 marker3))))
+ ;; Should only return markers with "work" tag
+ (should (= (length result) 2))
+ (should (member marker1 result))
+ (should-not (member marker2 result))
+ (should (member marker3 result))))))))
+ (test-chime-apply-whitelist-teardown)))
+
+(ert-deftest test-chime-apply-whitelist-keyword-and-tags-whitelist-uses-or-logic ()
+ "Test that both keyword and tags whitelists use OR logic."
+ (test-chime-apply-whitelist-setup)
+ (unwind-protect
+ (with-temp-buffer
+ (org-mode)
+ (insert "* TODO Task 1\n")
+ (let ((marker1 (copy-marker (point))))
+ (insert "* DONE Task 2\n")
+ (let ((marker2 (copy-marker (point))))
+ (insert "* NEXT Task 3\n")
+ (let ((marker3 (copy-marker (point)))
+ (chime-keyword-whitelist '("TODO"))
+ (chime-tags-whitelist '("urgent")))
+ ;; Mock functions
+ (cl-letf (((symbol-function 'org-entry-get)
+ (lambda (pom property &optional inherit literal-nil)
+ (when (equal property "TODO")
+ (cond
+ ((equal pom marker1) "TODO")
+ ((equal pom marker2) "DONE")
+ ((equal pom marker3) "NEXT")
+ (t nil)))))
+ ((symbol-function 'chime--get-tags)
+ (lambda (pom)
+ (cond
+ ((equal pom marker1) nil)
+ ((equal pom marker2) '("urgent"))
+ ((equal pom marker3) nil)
+ (t nil)))))
+ (let ((result (chime--apply-whitelist (list marker1 marker2 marker3))))
+ ;; Should return marker1 (TODO keyword) and marker2 (urgent tag)
+ (should (= (length result) 2))
+ (should (member marker1 result))
+ (should (member marker2 result))
+ (should-not (member marker3 result))))))))
+ (test-chime-apply-whitelist-teardown)))
+
+;;; Boundary Cases
+
+(ert-deftest test-chime-apply-whitelist-empty-markers-list-returns-empty ()
+ "Test that empty markers list returns empty."
+ (test-chime-apply-whitelist-setup)
+ (unwind-protect
+ (let ((chime-keyword-whitelist '("TODO"))
+ (result (chime--apply-whitelist '())))
+ (should (equal result '())))
+ (test-chime-apply-whitelist-teardown)))
+
+(ert-deftest test-chime-apply-whitelist-single-item-whitelist-works ()
+ "Test that single-item whitelist works correctly."
+ (test-chime-apply-whitelist-setup)
+ (unwind-protect
+ (with-temp-buffer
+ (org-mode)
+ (insert "* TODO Task 1\n")
+ (let ((marker1 (copy-marker (point))))
+ (insert "* DONE Task 2\n")
+ (let ((marker2 (copy-marker (point)))
+ (chime-keyword-whitelist '("TODO")))
+ (cl-letf (((symbol-function 'org-entry-get)
+ (lambda (pom property &optional inherit literal-nil)
+ (when (equal property "TODO")
+ (cond
+ ((equal pom marker1) "TODO")
+ ((equal pom marker2) "DONE")
+ (t nil))))))
+ (let ((result (chime--apply-whitelist (list marker1 marker2))))
+ (should (= (length result) 1))
+ (should (member marker1 result)))))))
+ (test-chime-apply-whitelist-teardown)))
+
+(ert-deftest test-chime-apply-whitelist-no-matching-markers-returns-empty ()
+ "Test that no matching markers returns empty list."
+ (test-chime-apply-whitelist-setup)
+ (unwind-protect
+ (with-temp-buffer
+ (org-mode)
+ (insert "* DONE Task 1\n")
+ (let ((marker1 (copy-marker (point))))
+ (insert "* CANCELLED Task 2\n")
+ (let ((marker2 (copy-marker (point)))
+ (chime-keyword-whitelist '("TODO")))
+ (cl-letf (((symbol-function 'org-entry-get)
+ (lambda (pom property &optional inherit literal-nil)
+ (when (equal property "TODO")
+ (cond
+ ((equal pom marker1) "DONE")
+ ((equal pom marker2) "CANCELLED")
+ (t nil))))))
+ (let ((result (chime--apply-whitelist (list marker1 marker2))))
+ (should (equal result '())))))))
+ (test-chime-apply-whitelist-teardown)))
+
+;;; Error Cases
+
+(ert-deftest test-chime-apply-whitelist-handles-nil-keyword-gracefully ()
+ "Test that nil keyword in marker is handled gracefully."
+ (test-chime-apply-whitelist-setup)
+ (unwind-protect
+ (with-temp-buffer
+ (org-mode)
+ (insert "* Entry without TODO keyword\n")
+ (let ((marker1 (copy-marker (point)))
+ (chime-keyword-whitelist '("TODO")))
+ (cl-letf (((symbol-function 'org-entry-get)
+ (lambda (pom property &optional inherit literal-nil)
+ nil)))
+ (let ((result (chime--apply-whitelist (list marker1))))
+ ;; Should filter out marker with nil keyword
+ (should (equal result '()))))))
+ (test-chime-apply-whitelist-teardown)))
+
+(ert-deftest test-chime-apply-whitelist-handles-nil-tags-gracefully ()
+ "Test that nil tags in marker is handled gracefully."
+ (test-chime-apply-whitelist-setup)
+ (unwind-protect
+ (with-temp-buffer
+ (org-mode)
+ (insert "* Entry without tags\n")
+ (let ((marker1 (copy-marker (point)))
+ (chime-tags-whitelist '("work")))
+ (cl-letf (((symbol-function 'chime--get-tags)
+ (lambda (pom) nil)))
+ (let ((result (chime--apply-whitelist (list marker1))))
+ ;; Should filter out marker with nil tags
+ (should (equal result '()))))))
+ (test-chime-apply-whitelist-teardown)))
+
+(provide 'test-chime-apply-whitelist)
+;;; test-chime-apply-whitelist.el ends here
diff --git a/tests/test-chime-check-event.el b/tests/test-chime-check-event.el
new file mode 100644
index 0000000..e6d645f
--- /dev/null
+++ b/tests/test-chime-check-event.el
@@ -0,0 +1,185 @@
+;;; test-chime-check-event.el --- Tests for chime--check-event -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2024 Craig Jennings
+
+;; Author: Craig Jennings <c@cjennings.net>
+
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Unit tests for chime--check-event function.
+;; Tests cover normal cases, boundary cases, and error cases.
+
+;;; Code:
+
+;; Initialize package system for batch mode
+(when noninteractive
+ (package-initialize))
+
+(require 'ert)
+
+;; Load dependencies required by chime
+(require 'dash)
+(require 'alert)
+(require 'async)
+(require 'org-agenda)
+
+;; Load chime from parent directory
+(load (expand-file-name "../chime.el") nil t)
+
+;; Load test utilities
+(require 'testutil-general (expand-file-name "testutil-general.el"))
+
+;;; Setup and Teardown
+
+(defun test-chime-check-event-setup ()
+ "Setup function run before each test."
+ (chime-create-test-base-dir))
+
+(defun test-chime-check-event-teardown ()
+ "Teardown function run after each test."
+ (chime-delete-test-base-dir))
+
+;;; Normal Cases
+
+(ert-deftest test-chime-check-event-single-notification-returns-message ()
+ "Test that single matching notification returns formatted message."
+ (test-chime-check-event-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ ;; Event at 14:10 (10 minutes from now)
+ (event-time (encode-time 0 10 14 24 10 2025))
+ (event `((times . ((("<2025-10-24 Fri 14:10>" . ,event-time))))
+ (title . "Team Meeting")
+ (intervals . (10))))
+ (result (chime--check-event event)))
+ ;; Should return list with one formatted message
+ (should (listp result))
+ (should (= 1 (length result)))
+ (should (stringp (car result)))
+ ;; Message should contain title and time information
+ (should (string-match-p "Team Meeting" (car result)))
+ (should (string-match-p "02:10 PM" (car result)))
+ (should (string-match-p "in 10 minutes" (car result))))
+ (test-chime-check-event-teardown)))
+
+(ert-deftest test-chime-check-event-multiple-notifications-returns-multiple-messages ()
+ "Test that multiple matching notifications return multiple formatted messages."
+ (test-chime-check-event-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ ;; Two events: 14:10 and 14:05
+ (event-time-1 (encode-time 0 10 14 24 10 2025))
+ (event-time-2 (encode-time 0 5 14 24 10 2025))
+ (event `((times . ((("<2025-10-24 Fri 14:10>" . ,event-time-1)
+ ("<2025-10-24 Fri 14:05>" . ,event-time-2))))
+ (title . "Important Call")
+ (intervals . (10 5)))) ; Both match
+ (result (chime--check-event event)))
+ ;; Should return two formatted messages
+ (should (listp result))
+ (should (= 2 (length result)))
+ (should (cl-every #'stringp result))
+ ;; Both should mention the title
+ (should (string-match-p "Important Call" (car result)))
+ (should (string-match-p "Important Call" (cadr result))))
+ (test-chime-check-event-teardown)))
+
+(ert-deftest test-chime-check-event-zero-interval-returns-right-now-message ()
+ "Test that zero interval produces 'right now' message."
+ (test-chime-check-event-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ ;; Event at exactly now
+ (event-time (encode-time 0 0 14 24 10 2025))
+ (event `((times . ((("<2025-10-24 Fri 14:00>" . ,event-time))))
+ (title . "Daily Standup")
+ (intervals . (0))))
+ (result (chime--check-event event)))
+ (should (listp result))
+ (should (= 1 (length result)))
+ (should (string-match-p "Daily Standup" (car result)))
+ (should (string-match-p "right now" (car result))))
+ (test-chime-check-event-teardown)))
+
+;;; Boundary Cases
+
+(ert-deftest test-chime-check-event-no-matching-notifications-returns-empty-list ()
+ "Test that event with no matching times returns empty list."
+ (test-chime-check-event-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ ;; Event at 14:20 (doesn't match 10 minute interval)
+ (event-time (encode-time 0 20 14 24 10 2025))
+ (event `((times . ((("<2025-10-24 Fri 14:20>" . ,event-time))))
+ (title . "Future Event")
+ (intervals . (10))))
+ (result (chime--check-event event)))
+ (should (listp result))
+ (should (= 0 (length result))))
+ (test-chime-check-event-teardown)))
+
+(ert-deftest test-chime-check-event-day-wide-event-returns-empty-list ()
+ "Test that day-wide event (no time) returns empty list."
+ (test-chime-check-event-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ (event-time (encode-time 0 0 14 24 10 2025))
+ (event `((times . ((("<2025-10-24 Fri>" . ,event-time))))
+ (title . "All Day Event")
+ (intervals . (10))))
+ (result (chime--check-event event)))
+ (should (listp result))
+ (should (= 0 (length result))))
+ (test-chime-check-event-teardown)))
+
+;;; Error Cases
+
+(ert-deftest test-chime-check-event-empty-times-returns-empty-list ()
+ "Test that event with no times returns empty list."
+ (test-chime-check-event-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ (event `((times . (()))
+ (title . "No Times Event")
+ (intervals . (10))))
+ (result (chime--check-event event)))
+ (should (listp result))
+ (should (= 0 (length result))))
+ (test-chime-check-event-teardown)))
+
+(ert-deftest test-chime-check-event-empty-intervals-returns-empty-list ()
+ "Test that event with no intervals returns empty list."
+ (test-chime-check-event-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ (event-time (encode-time 0 10 14 24 10 2025))
+ (event `((times . ((("<2025-10-24 Fri 14:10>" . ,event-time))))
+ (title . "No Intervals Event")
+ (intervals . ())))
+ (result (chime--check-event event)))
+ (should (listp result))
+ (should (= 0 (length result))))
+ (test-chime-check-event-teardown)))
+
+(provide 'test-chime-check-event)
+;;; test-chime-check-event.el ends here
diff --git a/tests/test-chime-extract-time.el b/tests/test-chime-extract-time.el
new file mode 100644
index 0000000..4041713
--- /dev/null
+++ b/tests/test-chime-extract-time.el
@@ -0,0 +1,388 @@
+;;; test-chime-extract-time.el --- Tests for chime--extract-time -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2024 Craig Jennings
+
+;; Author: Craig Jennings <c@cjennings.net>
+
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Unit tests for chime--extract-time function.
+;; Tests cover normal cases, boundary cases, and error cases.
+
+;;; Code:
+
+;; Initialize package system for batch mode
+(when noninteractive
+ (package-initialize))
+
+(require 'ert)
+
+;; Load dependencies required by chime
+(require 'dash)
+(require 'alert)
+(require 'async)
+(require 'org-agenda)
+
+;; Load chime from parent directory
+(load (expand-file-name "../chime.el") nil t)
+
+;; Load test utilities
+(require 'testutil-general (expand-file-name "testutil-general.el"))
+
+;;; Setup and Teardown
+
+(defun test-chime-extract-time-setup ()
+ "Setup function run before each test."
+ (chime-create-test-base-dir))
+
+(defun test-chime-extract-time-teardown ()
+ "Teardown function run after each test."
+ (chime-delete-test-base-dir))
+
+;;; Normal Cases
+
+(ert-deftest test-chime-extract-time-scheduled-timestamp-extracted ()
+ "Test that SCHEDULED timestamp is extracted correctly."
+ (test-chime-extract-time-setup)
+ (unwind-protect
+ (with-temp-buffer
+ (org-mode)
+ (insert "* TODO Test Task\n")
+ (let ((marker (copy-marker (point))))
+ (cl-letf (((symbol-function 'org-entry-get)
+ (lambda (pom property &optional inherit literal-nil)
+ (cond
+ ((and (equal pom marker) (equal property "SCHEDULED"))
+ "<2025-10-24 Fri 14:30>")
+ (t nil)))))
+ (let ((result (chime--extract-time marker)))
+ (should (listp result))
+ (should (= (length result) 1))
+ (should (equal (caar result) "<2025-10-24 Fri 14:30>"))
+ (should (listp (cdar result)))))))
+ (test-chime-extract-time-teardown)))
+
+(ert-deftest test-chime-extract-time-deadline-timestamp-extracted ()
+ "Test that DEADLINE timestamp is extracted correctly."
+ (test-chime-extract-time-setup)
+ (unwind-protect
+ (with-temp-buffer
+ (org-mode)
+ (insert "* TODO Test Task\n")
+ (let ((marker (copy-marker (point))))
+ (cl-letf (((symbol-function 'org-entry-get)
+ (lambda (pom property &optional inherit literal-nil)
+ (cond
+ ((and (equal pom marker) (equal property "DEADLINE"))
+ "<2025-10-24 Fri 16:00>")
+ (t nil)))))
+ (let ((result (chime--extract-time marker)))
+ (should (listp result))
+ (should (= (length result) 1))
+ (should (equal (caar result) "<2025-10-24 Fri 16:00>"))
+ (should (listp (cdar result)))))))
+ (test-chime-extract-time-teardown)))
+
+(ert-deftest test-chime-extract-time-plain-timestamp-extracted ()
+ "Test that plain TIMESTAMP is extracted correctly."
+ (test-chime-extract-time-setup)
+ (unwind-protect
+ (with-temp-buffer
+ (org-mode)
+ (insert "* Test Event\n")
+ (let ((marker (copy-marker (point))))
+ (cl-letf (((symbol-function 'org-entry-get)
+ (lambda (pom property &optional inherit literal-nil)
+ (cond
+ ((and (equal pom marker) (equal property "TIMESTAMP"))
+ "<2025-10-24 Fri 10:00>")
+ (t nil)))))
+ (let ((result (chime--extract-time marker)))
+ (should (listp result))
+ (should (= (length result) 1))
+ (should (equal (caar result) "<2025-10-24 Fri 10:00>"))
+ (should (listp (cdar result)))))))
+ (test-chime-extract-time-teardown)))
+
+(ert-deftest test-chime-extract-time-multiple-timestamps-all-extracted ()
+ "Test that multiple timestamps are all extracted."
+ (test-chime-extract-time-setup)
+ (unwind-protect
+ (with-temp-buffer
+ (org-mode)
+ (insert "* TODO Test Task\n")
+ (let ((marker (copy-marker (point))))
+ (cl-letf (((symbol-function 'org-entry-get)
+ (lambda (pom property &optional inherit literal-nil)
+ (cond
+ ((and (equal pom marker) (equal property "SCHEDULED"))
+ "<2025-10-24 Fri 14:30>")
+ ((and (equal pom marker) (equal property "DEADLINE"))
+ "<2025-10-24 Fri 16:00>")
+ (t nil)))))
+ (let ((result (chime--extract-time marker)))
+ (should (listp result))
+ (should (= (length result) 2))
+ ;; Check both timestamps are present
+ (should (--some (equal (car it) "<2025-10-24 Fri 14:30>") result))
+ (should (--some (equal (car it) "<2025-10-24 Fri 16:00>") result))))))
+ (test-chime-extract-time-teardown)))
+
+(ert-deftest test-chime-extract-time-all-three-timestamp-types-extracted ()
+ "Test that all three timestamp types can be extracted together."
+ (test-chime-extract-time-setup)
+ (unwind-protect
+ (with-temp-buffer
+ (org-mode)
+ (insert "* TODO Complex Task\n")
+ (let ((marker (copy-marker (point))))
+ (cl-letf (((symbol-function 'org-entry-get)
+ (lambda (pom property &optional inherit literal-nil)
+ (cond
+ ((and (equal pom marker) (equal property "SCHEDULED"))
+ "<2025-10-24 Fri 09:00>")
+ ((and (equal pom marker) (equal property "DEADLINE"))
+ "<2025-10-24 Fri 17:00>")
+ ((and (equal pom marker) (equal property "TIMESTAMP"))
+ "<2025-10-24 Fri 12:00>")
+ (t nil)))))
+ (let ((result (chime--extract-time marker)))
+ (should (listp result))
+ (should (= (length result) 3))))))
+ (test-chime-extract-time-teardown)))
+
+;;; Boundary Cases
+
+(ert-deftest test-chime-extract-time-no-timestamps-returns-empty ()
+ "Test that entry with no timestamps returns empty list."
+ (test-chime-extract-time-setup)
+ (unwind-protect
+ (with-temp-buffer
+ (org-mode)
+ (insert "* TODO Test Task\n")
+ (let ((marker (copy-marker (point))))
+ (cl-letf (((symbol-function 'org-entry-get)
+ (lambda (pom property &optional inherit literal-nil)
+ nil)))
+ (let ((result (chime--extract-time marker)))
+ (should (listp result))
+ (should (= (length result) 0))))))
+ (test-chime-extract-time-teardown)))
+
+(ert-deftest test-chime-extract-time-only-scheduled-extracted ()
+ "Test that only SCHEDULED is extracted when others are missing."
+ (test-chime-extract-time-setup)
+ (unwind-protect
+ (with-temp-buffer
+ (org-mode)
+ (insert "* TODO Test Task\n")
+ (let ((marker (copy-marker (point))))
+ (cl-letf (((symbol-function 'org-entry-get)
+ (lambda (pom property &optional inherit literal-nil)
+ (cond
+ ((and (equal pom marker) (equal property "SCHEDULED"))
+ "<2025-10-24 Fri 14:30>")
+ (t nil)))))
+ (let ((result (chime--extract-time marker)))
+ (should (= (length result) 1))
+ (should (equal (caar result) "<2025-10-24 Fri 14:30>"))))))
+ (test-chime-extract-time-teardown)))
+
+(ert-deftest test-chime-extract-time-only-deadline-extracted ()
+ "Test that only DEADLINE is extracted when others are missing."
+ (test-chime-extract-time-setup)
+ (unwind-protect
+ (with-temp-buffer
+ (org-mode)
+ (insert "* TODO Test Task\n")
+ (let ((marker (copy-marker (point))))
+ (cl-letf (((symbol-function 'org-entry-get)
+ (lambda (pom property &optional inherit literal-nil)
+ (cond
+ ((and (equal pom marker) (equal property "DEADLINE"))
+ "<2025-10-24 Fri 16:00>")
+ (t nil)))))
+ (let ((result (chime--extract-time marker)))
+ (should (= (length result) 1))
+ (should (equal (caar result) "<2025-10-24 Fri 16:00>"))))))
+ (test-chime-extract-time-teardown)))
+
+;;; Error Cases
+
+(ert-deftest test-chime-extract-time-malformed-timestamp-returns-nil-cdr ()
+ "Test that malformed timestamps return cons with nil cdr."
+ (test-chime-extract-time-setup)
+ (unwind-protect
+ (with-temp-buffer
+ (org-mode)
+ (insert "* TODO Test Task\n")
+ (let ((marker (copy-marker (point))))
+ (cl-letf (((symbol-function 'org-entry-get)
+ (lambda (pom property &optional inherit literal-nil)
+ (cond
+ ((and (equal pom marker) (equal property "SCHEDULED"))
+ "not-a-valid-timestamp")
+ ((and (equal pom marker) (equal property "DEADLINE"))
+ "<2025-10-24 Fri 16:00>")
+ (t nil)))))
+ (let ((result (chime--extract-time marker)))
+ ;; Should return both, but malformed one has nil cdr
+ (should (= (length result) 2))
+ ;; Find the malformed timestamp result
+ (let ((malformed (--find (equal (car it) "not-a-valid-timestamp") result)))
+ (should malformed)
+ (should-not (cdr malformed)))))))
+ (test-chime-extract-time-teardown)))
+
+(ert-deftest test-chime-extract-time-day-wide-timestamp-returns-nil-cdr ()
+ "Test that day-wide timestamps (no time) return cons with nil cdr."
+ (test-chime-extract-time-setup)
+ (unwind-protect
+ (with-temp-buffer
+ (org-mode)
+ (insert "* TODO Test Task\n")
+ (let ((marker (copy-marker (point))))
+ (cl-letf (((symbol-function 'org-entry-get)
+ (lambda (pom property &optional inherit literal-nil)
+ (cond
+ ((and (equal pom marker) (equal property "SCHEDULED"))
+ "<2025-10-24 Fri>") ; Day-wide, no time
+ ((and (equal pom marker) (equal property "DEADLINE"))
+ "<2025-10-24 Fri 16:00>") ; Has time
+ (t nil)))))
+ (let ((result (chime--extract-time marker)))
+ ;; Should return both timestamps
+ (should (= (length result) 2))
+ ;; Day-wide timestamp has nil cdr
+ (let ((day-wide (--find (equal (car it) "<2025-10-24 Fri>") result)))
+ (should day-wide)
+ (should-not (cdr day-wide)))
+ ;; Timed timestamp has valid cdr
+ (let ((timed (--find (equal (car it) "<2025-10-24 Fri 16:00>") result)))
+ (should timed)
+ (should (cdr timed)))))))
+ (test-chime-extract-time-teardown)))
+
+(ert-deftest test-chime-extract-time-empty-timestamp-string-returns-nil-cdr ()
+ "Test that empty timestamp strings return cons with nil cdr."
+ (test-chime-extract-time-setup)
+ (unwind-protect
+ (with-temp-buffer
+ (org-mode)
+ (insert "* TODO Test Task\n")
+ (let ((marker (copy-marker (point))))
+ (cl-letf (((symbol-function 'org-entry-get)
+ (lambda (pom property &optional inherit literal-nil)
+ (cond
+ ((and (equal pom marker) (equal property "SCHEDULED"))
+ "")
+ ((and (equal pom marker) (equal property "DEADLINE"))
+ "<2025-10-24 Fri 16:00>")
+ (t nil)))))
+ (let ((result (chime--extract-time marker)))
+ ;; Should return both entries
+ (should (= (length result) 2))
+ ;; Empty string has nil cdr
+ (let ((empty (--find (equal (car it) "") result)))
+ (should empty)
+ (should-not (cdr empty)))))))
+ (test-chime-extract-time-teardown)))
+
+(ert-deftest test-chime-extract-time-all-malformed-returns-cons-with-nil-cdrs ()
+ "Test that all malformed timestamps return cons with nil cdrs."
+ (test-chime-extract-time-setup)
+ (unwind-protect
+ (with-temp-buffer
+ (org-mode)
+ (insert "* TODO Test Task\n")
+ (let ((marker (copy-marker (point))))
+ (cl-letf (((symbol-function 'org-entry-get)
+ (lambda (pom property &optional inherit literal-nil)
+ (cond
+ ((and (equal pom marker) (equal property "SCHEDULED"))
+ "not-valid")
+ ((and (equal pom marker) (equal property "DEADLINE"))
+ "also-not-valid")
+ ((and (equal pom marker) (equal property "TIMESTAMP"))
+ "<2025-10-24 Fri>") ; Day-wide
+ (t nil)))))
+ (let ((result (chime--extract-time marker)))
+ ;; Should return 3 entries, all with nil cdr
+ (should (= (length result) 3))
+ (should (--every (not (cdr it)) result))))))
+ (test-chime-extract-time-teardown)))
+
+;;; org-gcal Integration Tests
+
+(ert-deftest test-chime-extract-time-org-gcal-time-range-format ()
+ "Test extraction of org-gcal style timestamp with time range.
+org-gcal uses format like <2025-10-24 Fri 17:30-18:00> with HH:MM-HH:MM range."
+ (test-chime-extract-time-setup)
+ (unwind-protect
+ (with-temp-buffer
+ (org-mode)
+ (insert "* Testing Round Trip\n")
+ (let ((marker (copy-marker (point))))
+ (cl-letf (((symbol-function 'org-entry-get)
+ (lambda (pom property &optional inherit literal-nil)
+ (cond
+ ((and (equal pom marker) (equal property "TIMESTAMP"))
+ "<2025-10-24 Fri 17:30-18:00>")
+ (t nil)))))
+ (let ((result (chime--extract-time marker)))
+ (should (listp result))
+ (should (>= (length result) 1))
+ ;; Should extract the timestamp string
+ (should (equal (caar result) "<2025-10-24 Fri 17:30-18:00>"))
+ ;; Should have parsed time value (not nil)
+ (should (listp (cdar result)))
+ (should (cdar result))))))
+ (test-chime-extract-time-teardown)))
+
+(ert-deftest test-chime-extract-time-org-gcal-in-drawer ()
+ "Test extraction of timestamp inside org-gcal drawer.
+org-gcal stores timestamps in :org-gcal: drawers which should still be detected."
+ (test-chime-extract-time-setup)
+ (unwind-protect
+ (with-temp-buffer
+ (org-mode)
+ (insert "* Testing Chime!\n")
+ (insert ":PROPERTIES:\n")
+ (insert ":ETag: \"3522688202987102\"\n")
+ (insert ":calendar-id: user@example.com\n")
+ (insert ":entry-id: abc123/user@example.com\n")
+ (insert ":org-gcal-managed: gcal\n")
+ (insert ":END:\n")
+ (insert ":org-gcal:\n")
+ (insert "<2025-10-24 Fri 17:30-18:00>\n")
+ (insert ":END:\n")
+ (goto-char (point-min))
+ (let ((marker (copy-marker (point))))
+ (cl-letf (((symbol-function 'org-entry-get)
+ (lambda (pom property &optional inherit literal-nil)
+ (cond
+ ((and (equal pom marker) (equal property "TIMESTAMP"))
+ "<2025-10-24 Fri 17:30-18:00>")
+ (t nil)))))
+ (let ((result (chime--extract-time marker)))
+ (should (listp result))
+ (should (>= (length result) 1))
+ (should (equal (caar result) "<2025-10-24 Fri 17:30-18:00>"))
+ (should (cdar result))))))
+ (test-chime-extract-time-teardown)))
+
+(provide 'test-chime-extract-time)
+;;; test-chime-extract-time.el ends here
diff --git a/tests/test-chime-has-timestamp.el b/tests/test-chime-has-timestamp.el
new file mode 100644
index 0000000..7cc7831
--- /dev/null
+++ b/tests/test-chime-has-timestamp.el
@@ -0,0 +1,227 @@
+;;; test-chime-has-timestamp.el --- Tests for chime--has-timestamp -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2024 Craig Jennings
+
+;; Author: Craig Jennings <c@cjennings.net>
+
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Unit tests for chime--has-timestamp function.
+;; Tests cover normal cases, boundary cases, and error cases.
+
+;;; Code:
+
+;; Initialize package system for batch mode
+(when noninteractive
+ (package-initialize))
+
+(require 'ert)
+
+;; Load dependencies required by chime
+(require 'dash)
+(require 'alert)
+(require 'async)
+(require 'org-agenda)
+
+;; Load chime from parent directory
+(load (expand-file-name "../chime.el") nil t)
+
+;; Load test utilities
+(require 'testutil-general (expand-file-name "testutil-general.el"))
+
+;;; Setup and Teardown
+
+(defun test-chime-has-timestamp-setup ()
+ "Setup function run before each test."
+ (chime-create-test-base-dir))
+
+(defun test-chime-has-timestamp-teardown ()
+ "Teardown function run after each test."
+ (chime-delete-test-base-dir))
+
+;;; Normal Cases
+
+(ert-deftest test-chime-has-timestamp-standard-timestamp-with-time-returns-non-nil ()
+ "Test that standard timestamp with time returns non-nil."
+ (test-chime-has-timestamp-setup)
+ (unwind-protect
+ (let* ((timestamp "<2025-10-24 Fri 14:30>")
+ (result (chime--has-timestamp timestamp)))
+ (should result))
+ (test-chime-has-timestamp-teardown)))
+
+(ert-deftest test-chime-has-timestamp-timestamp-without-brackets-returns-non-nil ()
+ "Test that timestamp without brackets but with time returns non-nil."
+ (test-chime-has-timestamp-setup)
+ (unwind-protect
+ (let* ((timestamp "2025-10-24 Fri 14:30")
+ (result (chime--has-timestamp timestamp)))
+ (should result))
+ (test-chime-has-timestamp-teardown)))
+
+(ert-deftest test-chime-has-timestamp-timestamp-with-time-range-returns-non-nil ()
+ "Test that timestamp with time range returns non-nil."
+ (test-chime-has-timestamp-setup)
+ (unwind-protect
+ (let* ((timestamp "<2025-10-24 Fri 14:00-15:30>")
+ (result (chime--has-timestamp timestamp)))
+ (should result))
+ (test-chime-has-timestamp-teardown)))
+
+(ert-deftest test-chime-has-timestamp-scheduled-with-time-returns-non-nil ()
+ "Test that SCHEDULED timestamp with time returns non-nil."
+ (test-chime-has-timestamp-setup)
+ (unwind-protect
+ (let* ((timestamp "SCHEDULED: <2025-10-24 Fri 09:00>")
+ (result (chime--has-timestamp timestamp)))
+ (should result))
+ (test-chime-has-timestamp-teardown)))
+
+(ert-deftest test-chime-has-timestamp-deadline-with-time-returns-non-nil ()
+ "Test that DEADLINE timestamp with time returns non-nil."
+ (test-chime-has-timestamp-setup)
+ (unwind-protect
+ (let* ((timestamp "DEADLINE: <2025-10-24 Fri 17:00>")
+ (result (chime--has-timestamp timestamp)))
+ (should result))
+ (test-chime-has-timestamp-teardown)))
+
+(ert-deftest test-chime-has-timestamp-repeater-with-time-returns-non-nil ()
+ "Test that timestamp with repeater and time returns non-nil."
+ (test-chime-has-timestamp-setup)
+ (unwind-protect
+ (let* ((timestamp "<2025-10-24 Fri 14:00 +1w>")
+ (result (chime--has-timestamp timestamp)))
+ (should result))
+ (test-chime-has-timestamp-teardown)))
+
+(ert-deftest test-chime-has-timestamp-midnight-timestamp-returns-non-nil ()
+ "Test that midnight timestamp (00:00) returns non-nil."
+ (test-chime-has-timestamp-setup)
+ (unwind-protect
+ (let* ((timestamp "<2025-10-24 Fri 00:00>")
+ (result (chime--has-timestamp timestamp)))
+ (should result))
+ (test-chime-has-timestamp-teardown)))
+
+;;; Boundary Cases
+
+(ert-deftest test-chime-has-timestamp-day-wide-timestamp-returns-nil ()
+ "Test that day-wide timestamp without time returns nil."
+ (test-chime-has-timestamp-setup)
+ (unwind-protect
+ (let* ((timestamp "<2025-10-24 Fri>")
+ (result (chime--has-timestamp timestamp)))
+ (should-not result))
+ (test-chime-has-timestamp-teardown)))
+
+(ert-deftest test-chime-has-timestamp-date-only-returns-nil ()
+ "Test that date-only timestamp without day name returns nil."
+ (test-chime-has-timestamp-setup)
+ (unwind-protect
+ (let* ((timestamp "<2025-10-24>")
+ (result (chime--has-timestamp timestamp)))
+ (should-not result))
+ (test-chime-has-timestamp-teardown)))
+
+(ert-deftest test-chime-has-timestamp-single-digit-hour-returns-non-nil ()
+ "Test that timestamp with single-digit hour returns non-nil."
+ (test-chime-has-timestamp-setup)
+ (unwind-protect
+ (let* ((timestamp "<2025-10-24 Fri 9:00>")
+ (result (chime--has-timestamp timestamp)))
+ (should result))
+ (test-chime-has-timestamp-teardown)))
+
+(ert-deftest test-chime-has-timestamp-embedded-in-text-returns-non-nil ()
+ "Test that timestamp embedded in text returns non-nil."
+ (test-chime-has-timestamp-setup)
+ (unwind-protect
+ (let* ((timestamp "Meeting scheduled for <2025-10-24 Fri 14:00> in conference room")
+ (result (chime--has-timestamp timestamp)))
+ (should result))
+ (test-chime-has-timestamp-teardown)))
+
+(ert-deftest test-chime-has-timestamp-multiple-timestamps-returns-non-nil ()
+ "Test that string with multiple timestamps returns non-nil for first match."
+ (test-chime-has-timestamp-setup)
+ (unwind-protect
+ (let* ((timestamp "<2025-10-24 Fri 14:00> and <2025-10-25 Sat 15:00>")
+ (result (chime--has-timestamp timestamp)))
+ (should result))
+ (test-chime-has-timestamp-teardown)))
+
+;;; Error Cases
+
+(ert-deftest test-chime-has-timestamp-empty-string-returns-nil ()
+ "Test that empty string returns nil."
+ (test-chime-has-timestamp-setup)
+ (unwind-protect
+ (let* ((timestamp "")
+ (result (chime--has-timestamp timestamp)))
+ (should-not result))
+ (test-chime-has-timestamp-teardown)))
+
+(ert-deftest test-chime-has-timestamp-nil-input-returns-nil ()
+ "Test that nil input returns nil."
+ (test-chime-has-timestamp-setup)
+ (unwind-protect
+ (let* ((timestamp nil)
+ (result (chime--has-timestamp timestamp)))
+ (should-not result))
+ (test-chime-has-timestamp-teardown)))
+
+(ert-deftest test-chime-has-timestamp-no-timestamp-returns-nil ()
+ "Test that string without timestamp returns nil."
+ (test-chime-has-timestamp-setup)
+ (unwind-protect
+ (let* ((timestamp "Just a regular string with no timestamp")
+ (result (chime--has-timestamp timestamp)))
+ (should-not result))
+ (test-chime-has-timestamp-teardown)))
+
+(ert-deftest test-chime-has-timestamp-invalid-format-returns-nil ()
+ "Test that invalid timestamp format returns nil."
+ (test-chime-has-timestamp-setup)
+ (unwind-protect
+ (let* ((timestamp "<10-24-2025 Fri 14:00>")
+ (result (chime--has-timestamp timestamp)))
+ (should-not result))
+ (test-chime-has-timestamp-teardown)))
+
+(ert-deftest test-chime-has-timestamp-partial-timestamp-returns-nil ()
+ "Test that partial timestamp returns nil."
+ (test-chime-has-timestamp-setup)
+ (unwind-protect
+ (let* ((timestamp "<2025-10-24")
+ (result (chime--has-timestamp timestamp)))
+ (should-not result))
+ (test-chime-has-timestamp-teardown)))
+
+;;; org-gcal Integration Tests
+
+(ert-deftest test-chime-has-timestamp-org-gcal-time-range-returns-non-nil ()
+ "Test that org-gcal time range format is detected.
+org-gcal uses format like <2025-10-24 Fri 17:30-18:00> which should be detected."
+ (test-chime-has-timestamp-setup)
+ (unwind-protect
+ (let* ((timestamp "<2025-10-24 Fri 17:30-18:00>")
+ (result (chime--has-timestamp timestamp)))
+ (should result))
+ (test-chime-has-timestamp-teardown)))
+
+(provide 'test-chime-has-timestamp)
+;;; test-chime-has-timestamp.el ends here
diff --git a/tests/test-chime-notification-text.el b/tests/test-chime-notification-text.el
new file mode 100644
index 0000000..7d7d192
--- /dev/null
+++ b/tests/test-chime-notification-text.el
@@ -0,0 +1,204 @@
+;;; test-chime-notification-text.el --- Tests for chime--notification-text -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2024 Craig Jennings
+
+;; Author: Craig Jennings <c@cjennings.net>
+
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Unit tests for chime--notification-text function.
+;; Tests cover normal cases, boundary cases, and error cases.
+
+;;; Code:
+
+;; Initialize package system for batch mode
+(when noninteractive
+ (package-initialize))
+
+(require 'ert)
+
+;; Load dependencies required by chime
+(require 'dash)
+(require 'alert)
+(require 'async)
+(require 'org-agenda)
+
+;; Load chime from parent directory
+(load (expand-file-name "../chime.el") nil t)
+
+;; Load test utilities
+(require 'testutil-general (expand-file-name "testutil-general.el"))
+
+;;; Setup and Teardown
+
+(defun test-chime-notification-text-setup ()
+ "Setup function run before each test."
+ (chime-create-test-base-dir)
+ ;; Reset display format to default
+ (setq chime-display-time-format-string "%I:%M %p"))
+
+(defun test-chime-notification-text-teardown ()
+ "Teardown function run after each test."
+ (chime-delete-test-base-dir))
+
+;;; Normal Cases
+
+(ert-deftest test-chime-notification-text-standard-event-formats-correctly ()
+ "Test that standard event formats correctly."
+ (test-chime-notification-text-setup)
+ (unwind-protect
+ (let* ((str-interval '("<2025-10-24 Fri 14:30>" . 10))
+ (event '((title . "Team Meeting")))
+ (result (chime--notification-text str-interval event)))
+ ;; Should format: "Team Meeting at 02:30 PM (in X minutes)"
+ (should (stringp result))
+ (should (string-match-p "Team Meeting" result))
+ (should (string-match-p "02:30 PM" result))
+ (should (string-match-p "in 10 minutes" result)))
+ (test-chime-notification-text-teardown)))
+
+(ert-deftest test-chime-notification-text-morning-time-formats-with-am ()
+ "Test that morning time uses AM."
+ (test-chime-notification-text-setup)
+ (unwind-protect
+ (let* ((str-interval '("<2025-10-24 Fri 09:15>" . 5))
+ (event '((title . "Standup")))
+ (result (chime--notification-text str-interval event)))
+ (should (string-match-p "Standup" result))
+ (should (string-match-p "09:15 AM" result))
+ (should (string-match-p "in 5 minutes" result)))
+ (test-chime-notification-text-teardown)))
+
+(ert-deftest test-chime-notification-text-midnight-formats-correctly ()
+ "Test that midnight time formats correctly."
+ (test-chime-notification-text-setup)
+ (unwind-protect
+ (let* ((str-interval '("<2025-10-24 Fri 00:00>" . 30))
+ (event '((title . "Midnight Event")))
+ (result (chime--notification-text str-interval event)))
+ (should (string-match-p "Midnight Event" result))
+ (should (string-match-p "12:00 AM" result))
+ (should (string-match-p "in 30 minutes" result)))
+ (test-chime-notification-text-teardown)))
+
+(ert-deftest test-chime-notification-text-noon-formats-correctly ()
+ "Test that noon time formats correctly."
+ (test-chime-notification-text-setup)
+ (unwind-protect
+ (let* ((str-interval '("<2025-10-24 Fri 12:00>" . 15))
+ (event '((title . "Lunch")))
+ (result (chime--notification-text str-interval event)))
+ (should (string-match-p "Lunch" result))
+ (should (string-match-p "12:00 PM" result))
+ (should (string-match-p "in 15 minutes" result)))
+ (test-chime-notification-text-teardown)))
+
+(ert-deftest test-chime-notification-text-zero-minutes-shows-right-now ()
+ "Test that zero minutes shows 'right now'."
+ (test-chime-notification-text-setup)
+ (unwind-protect
+ (let* ((str-interval '("<2025-10-24 Fri 14:00>" . 0))
+ (event '((title . "Current Event")))
+ (result (chime--notification-text str-interval event)))
+ (should (string-match-p "Current Event" result))
+ (should (string-match-p "02:00 PM" result))
+ (should (string-match-p "right now" result)))
+ (test-chime-notification-text-teardown)))
+
+;;; Boundary Cases
+
+(ert-deftest test-chime-notification-text-very-long-title-included ()
+ "Test that very long titles are included in full."
+ (test-chime-notification-text-setup)
+ (unwind-protect
+ (let* ((str-interval '("<2025-10-24 Fri 15:45>" . 20))
+ (long-title "This is a very long event title that contains many words and might wrap in the notification display")
+ (event `((title . ,long-title)))
+ (result (chime--notification-text str-interval event)))
+ ;; Should include the full title
+ (should (string-match-p long-title result))
+ (should (string-match-p "03:45 PM" result))
+ (should (string-match-p "in 20 minutes" result)))
+ (test-chime-notification-text-teardown)))
+
+(ert-deftest test-chime-notification-text-title-with-special-characters ()
+ "Test that titles with special characters work correctly."
+ (test-chime-notification-text-setup)
+ (unwind-protect
+ (let* ((str-interval '("<2025-10-24 Fri 16:30>" . 5))
+ (event '((title . "Review: Alice's PR #123 (urgent!)")))
+ (result (chime--notification-text str-interval event)))
+ (should (string-match-p "Review: Alice's PR #123 (urgent!)" result))
+ (should (string-match-p "04:30 PM" result)))
+ (test-chime-notification-text-teardown)))
+
+(ert-deftest test-chime-notification-text-custom-time-format ()
+ "Test that custom time format string is respected."
+ (test-chime-notification-text-setup)
+ (unwind-protect
+ (let* ((str-interval '("<2025-10-24 Fri 14:30>" . 10))
+ (event '((title . "Meeting")))
+ (chime-display-time-format-string "%H:%M") ; 24-hour format
+ (result (chime--notification-text str-interval event)))
+ ;; Should use 24-hour format
+ (should (string-match-p "Meeting" result))
+ (should (string-match-p "14:30" result))
+ (should-not (string-match-p "PM" result)))
+ (test-chime-notification-text-teardown)))
+
+(ert-deftest test-chime-notification-text-large-interval-shows-hours ()
+ "Test that large intervals show hours."
+ (test-chime-notification-text-setup)
+ (unwind-protect
+ (let* ((str-interval '("<2025-10-24 Fri 18:00>" . 120)) ; 2 hours
+ (event '((title . "Evening Event")))
+ (result (chime--notification-text str-interval event)))
+ (should (string-match-p "Evening Event" result))
+ (should (string-match-p "06:00 PM" result))
+ ;; Should show hours format
+ (should (string-match-p "in 2 hours" result)))
+ (test-chime-notification-text-teardown)))
+
+;;; Error Cases
+
+(ert-deftest test-chime-notification-text-empty-title-shows-empty ()
+ "Test that empty title still generates output."
+ (test-chime-notification-text-setup)
+ (unwind-protect
+ (let* ((str-interval '("<2025-10-24 Fri 14:30>" . 10))
+ (event '((title . "")))
+ (result (chime--notification-text str-interval event)))
+ ;; Should still format, even with empty title
+ (should (stringp result))
+ (should (string-match-p "02:30 PM" result))
+ (should (string-match-p "in 10 minutes" result)))
+ (test-chime-notification-text-teardown)))
+
+(ert-deftest test-chime-notification-text-missing-title-shows-nil ()
+ "Test that missing title shows nil in output."
+ (test-chime-notification-text-setup)
+ (unwind-protect
+ (let* ((str-interval '("<2025-10-24 Fri 14:30>" . 10))
+ (event '()) ; No title
+ (result (chime--notification-text str-interval event)))
+ ;; Should still generate output with nil title
+ (should (stringp result))
+ (should (string-match-p "02:30 PM" result))
+ (should (string-match-p "in 10 minutes" result)))
+ (test-chime-notification-text-teardown)))
+
+(provide 'test-chime-notification-text)
+;;; test-chime-notification-text.el ends here
diff --git a/tests/test-chime-notifications.el b/tests/test-chime-notifications.el
new file mode 100644
index 0000000..f3aa5d7
--- /dev/null
+++ b/tests/test-chime-notifications.el
@@ -0,0 +1,227 @@
+;;; test-chime-notifications.el --- Tests for chime--notifications -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2024 Craig Jennings
+
+;; Author: Craig Jennings <c@cjennings.net>
+
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Unit tests for chime--notifications function.
+;; Tests cover normal cases, boundary cases, and error cases.
+
+;;; Code:
+
+;; Initialize package system for batch mode
+(when noninteractive
+ (package-initialize))
+
+(require 'ert)
+
+;; Load dependencies required by chime
+(require 'dash)
+(require 'alert)
+(require 'async)
+(require 'org-agenda)
+
+;; Load chime from parent directory
+(load (expand-file-name "../chime.el") nil t)
+
+;; Load test utilities
+(require 'testutil-general (expand-file-name "testutil-general.el"))
+
+;;; Setup and Teardown
+
+(defun test-chime-notifications-setup ()
+ "Setup function run before each test."
+ (chime-create-test-base-dir))
+
+(defun test-chime-notifications-teardown ()
+ "Teardown function run after each test."
+ (chime-delete-test-base-dir))
+
+;;; Normal Cases
+
+(ert-deftest test-chime-notifications-single-time-single-interval-returns-pair ()
+ "Test that single time with single interval returns one notification pair."
+ (test-chime-notifications-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ ;; Event at 14:10 (10 minutes from now)
+ (event-time (encode-time 0 10 14 24 10 2025))
+ (event `((times . ((("<2025-10-24 Fri 14:10>" . ,event-time))))
+ (title . "Test Event")
+ (intervals . (10))))
+ (result (chime--notifications event)))
+ ;; Should return list with one pair
+ (should (listp result))
+ (should (= 1 (length result))))
+ (test-chime-notifications-teardown)))
+
+(ert-deftest test-chime-notifications-single-time-multiple-intervals-returns-multiple-pairs ()
+ "Test that single time with multiple intervals returns multiple notification pairs."
+ (test-chime-notifications-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ ;; Event at 14:10
+ (event-time (encode-time 0 10 14 24 10 2025))
+ (event `((times . ((("<2025-10-24 Fri 14:10>" . ,event-time))))
+ (title . "Test Event")
+ (intervals . (10 5)))) ; Two intervals, only 10 matches
+ (result (chime--notifications event)))
+ ;; Should return only matching interval
+ (should (listp result))
+ (should (= 1 (length result))))
+ (test-chime-notifications-teardown)))
+
+(ert-deftest test-chime-notifications-multiple-times-single-interval-returns-matching-pairs ()
+ "Test that multiple times with single interval returns matching notifications."
+ (test-chime-notifications-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ ;; Two events: one at 14:10, one at 14:05
+ (event-time-1 (encode-time 0 10 14 24 10 2025))
+ (event-time-2 (encode-time 0 5 14 24 10 2025))
+ (event `((times . ((("<2025-10-24 Fri 14:10>" . ,event-time-1)
+ ("<2025-10-24 Fri 14:05>" . ,event-time-2))))
+ (title . "Test Event")
+ (intervals . (10)))) ; Only first time matches
+ (result (chime--notifications event)))
+ ;; Should return only matching time
+ (should (listp result))
+ (should (= 1 (length result))))
+ (test-chime-notifications-teardown)))
+
+(ert-deftest test-chime-notifications-multiple-times-multiple-intervals-returns-all-matches ()
+ "Test that multiple times and intervals return all matching combinations."
+ (test-chime-notifications-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ ;; Event at 14:10 and 14:05
+ (event-time-1 (encode-time 0 10 14 24 10 2025))
+ (event-time-2 (encode-time 0 5 14 24 10 2025))
+ (event `((times . ((("<2025-10-24 Fri 14:10>" . ,event-time-1)
+ ("<2025-10-24 Fri 14:05>" . ,event-time-2))))
+ (title . "Test Event")
+ (intervals . (10 5)))) ; Both match (10 with first, 5 with second)
+ (result (chime--notifications event)))
+ ;; Should return both matching pairs
+ (should (listp result))
+ (should (= 2 (length result))))
+ (test-chime-notifications-teardown)))
+
+(ert-deftest test-chime-notifications-zero-interval-returns-current-time-match ()
+ "Test that zero interval (notify now) works correctly."
+ (test-chime-notifications-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ ;; Event at exactly current time
+ (event-time (encode-time 0 0 14 24 10 2025))
+ (event `((times . ((("<2025-10-24 Fri 14:00>" . ,event-time))))
+ (title . "Test Event")
+ (intervals . (0))))
+ (result (chime--notifications event)))
+ ;; Should return one matching pair
+ (should (listp result))
+ (should (= 1 (length result))))
+ (test-chime-notifications-teardown)))
+
+(ert-deftest test-chime-notifications-filters-day-wide-events ()
+ "Test that day-wide events (without time) are filtered out."
+ (test-chime-notifications-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ ;; Mix of day-wide and timed events
+ (event-time (encode-time 0 10 14 24 10 2025))
+ (event `((times . ((("<2025-10-24 Fri>" . ,event-time) ; Day-wide
+ ("<2025-10-24 Fri 14:10>" . ,event-time)))) ; Timed
+ (title . "Test Event")
+ (intervals . (10))))
+ (result (chime--notifications event)))
+ ;; Should return only timed event
+ (should (listp result))
+ (should (= 1 (length result))))
+ (test-chime-notifications-teardown)))
+
+;;; Boundary Cases
+
+(ert-deftest test-chime-notifications-empty-times-returns-empty-list ()
+ "Test that event with no times returns empty list."
+ (test-chime-notifications-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ (event `((times . (()))
+ (title . "Test Event")
+ (intervals . (10))))
+ (result (chime--notifications event)))
+ (should (listp result))
+ (should (= 0 (length result))))
+ (test-chime-notifications-teardown)))
+
+(ert-deftest test-chime-notifications-empty-intervals-returns-empty-list ()
+ "Test that event with no intervals returns empty list."
+ (test-chime-notifications-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ (event-time (encode-time 0 10 14 24 10 2025))
+ (event `((times . ((("<2025-10-24 Fri 14:10>" . ,event-time))))
+ (title . "Test Event")
+ (intervals . ())))
+ (result (chime--notifications event)))
+ (should (listp result))
+ (should (= 0 (length result))))
+ (test-chime-notifications-teardown)))
+
+;;; Error Cases
+
+(ert-deftest test-chime-notifications-nil-times-returns-empty-list ()
+ "Test that event with nil times returns empty list."
+ (test-chime-notifications-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ (event `((times . (nil))
+ (title . "Test Event")
+ (intervals . (10))))
+ (result (chime--notifications event)))
+ (should (listp result))
+ (should (= 0 (length result))))
+ (test-chime-notifications-teardown)))
+
+(ert-deftest test-chime-notifications-nil-intervals-returns-empty-list ()
+ "Test that event with nil intervals returns empty list."
+ (test-chime-notifications-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ (event-time (encode-time 0 10 14 24 10 2025))
+ (event `((times . ((("<2025-10-24 Fri 14:10>" . ,event-time))))
+ (title . "Test Event")
+ (intervals . nil)))
+ (result (chime--notifications event)))
+ (should (listp result))
+ (should (= 0 (length result))))
+ (test-chime-notifications-teardown)))
+
+(provide 'test-chime-notifications)
+;;; test-chime-notifications.el ends here
diff --git a/tests/test-chime-notify.el b/tests/test-chime-notify.el
new file mode 100644
index 0000000..451508d
--- /dev/null
+++ b/tests/test-chime-notify.el
@@ -0,0 +1,244 @@
+;;; test-chime-notify.el --- Tests for chime--notify -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2024 Craig Jennings
+
+;; Author: Craig Jennings <c@cjennings.net>
+
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Unit tests for chime--notify function.
+;; Tests cover normal cases, boundary cases, and error cases.
+
+;;; Code:
+
+;; Initialize package system for batch mode
+(when noninteractive
+ (package-initialize))
+
+(require 'ert)
+
+;; Load dependencies required by chime
+(require 'dash)
+(require 'alert)
+(require 'async)
+(require 'org-agenda)
+
+;; Load chime from parent directory
+(load (expand-file-name "../chime.el") nil t)
+
+;; Load test utilities
+(require 'testutil-general (expand-file-name "testutil-general.el"))
+
+;;; Setup and Teardown
+
+(defun test-chime-notify-setup ()
+ "Setup function run before each test."
+ (chime-create-test-base-dir)
+ ;; Reset notification settings
+ (setq chime-notification-title "Agenda")
+ (setq chime-notification-icon nil)
+ (setq chime-alert-severity 'medium)
+ (setq chime-extra-alert-plist nil)
+ (setq chime-play-sound t)
+ ;; Use a simple test path for sound file
+ (setq chime-sound-file "/tmp/test-chime.wav"))
+
+(defun test-chime-notify-teardown ()
+ "Teardown function run after each test."
+ (chime-delete-test-base-dir))
+
+;;; Normal Cases
+
+(ert-deftest test-chime-notify-plays-sound-when-enabled-and-file-exists ()
+ "Test that sound is played when enabled and file exists."
+ (test-chime-notify-setup)
+ (unwind-protect
+ (let ((sound-played nil)
+ (alert-called nil)
+ (alert-message nil))
+ (cl-letf* ((chime-play-sound t)
+ (chime-sound-file (expand-file-name "test-sound.wav" chime-test-base-dir))
+ ;; Mock file-exists-p to return t
+ ((symbol-function 'file-exists-p) (lambda (file) t))
+ ;; Mock play-sound-file to track if called
+ ((symbol-function 'play-sound-file)
+ (lambda (file)
+ (setq sound-played t)))
+ ;; Mock alert to track if called
+ ((symbol-function 'alert)
+ (lambda (msg &rest args)
+ (setq alert-called t)
+ (setq alert-message msg))))
+ (chime--notify "Team Meeting at 02:10 PM")
+ ;; Should play sound
+ (should sound-played)
+ ;; Should show alert
+ (should alert-called)
+ (should (equal alert-message "Team Meeting at 02:10 PM"))))
+ (test-chime-notify-teardown)))
+
+(ert-deftest test-chime-notify-uses-beep-when-no-sound-file-specified ()
+ "Test that beep is used when chime-sound-file is nil."
+ (test-chime-notify-setup)
+ (unwind-protect
+ (let ((beep-called nil)
+ (alert-called nil))
+ (cl-letf* ((chime-play-sound t)
+ (chime-sound-file nil)
+ ;; Mock beep to track if called
+ ((symbol-function 'beep)
+ (lambda () (setq beep-called t)))
+ ;; Mock alert
+ ((symbol-function 'alert)
+ (lambda (msg &rest args) (setq alert-called t))))
+ (chime--notify "Standup in 5 minutes")
+ ;; Should call beep
+ (should beep-called)
+ ;; Should show alert
+ (should alert-called)))
+ (test-chime-notify-teardown)))
+
+(ert-deftest test-chime-notify-no-sound-when-disabled ()
+ "Test that no sound is played when chime-play-sound is nil."
+ (test-chime-notify-setup)
+ (unwind-protect
+ (let ((sound-played nil)
+ (beep-called nil)
+ (alert-called nil))
+ (cl-letf* ((chime-play-sound nil)
+ ((symbol-function 'play-sound-file)
+ (lambda (file) (setq sound-played t)))
+ ((symbol-function 'beep)
+ (lambda () (setq beep-called t)))
+ ((symbol-function 'alert)
+ (lambda (msg &rest args) (setq alert-called t))))
+ (chime--notify "Daily Standup")
+ ;; Should NOT play sound or beep
+ (should-not sound-played)
+ (should-not beep-called)
+ ;; Should still show alert
+ (should alert-called)))
+ (test-chime-notify-teardown)))
+
+(ert-deftest test-chime-notify-passes-correct-parameters-to-alert ()
+ "Test that alert is called with correct parameters."
+ (test-chime-notify-setup)
+ (unwind-protect
+ (let ((alert-params nil))
+ (cl-letf* ((chime-play-sound nil)
+ (chime-notification-title "Custom Title")
+ (chime-notification-icon "/path/to/icon.png")
+ (chime-alert-severity 'high)
+ (chime-extra-alert-plist '(:persistent t))
+ ;; Mock alert to capture parameters
+ ((symbol-function 'alert)
+ (lambda (msg &rest args) (setq alert-params args))))
+ (chime--notify "Test Event")
+ ;; Verify alert was called with correct parameters
+ (should (equal (plist-get alert-params :title) "Custom Title"))
+ (should (equal (plist-get alert-params :icon) "/path/to/icon.png"))
+ (should (equal (plist-get alert-params :severity) 'high))
+ (should (equal (plist-get alert-params :category) 'chime))
+ ;; Extra plist should be merged in
+ (should (equal (plist-get alert-params :persistent) t))))
+ (test-chime-notify-teardown)))
+
+;;; Boundary Cases
+
+(ert-deftest test-chime-notify-empty-message-still-notifies ()
+ "Test that empty message still triggers notification."
+ (test-chime-notify-setup)
+ (unwind-protect
+ (let ((alert-called nil)
+ (alert-message nil))
+ (cl-letf* ((chime-play-sound nil)
+ ((symbol-function 'alert)
+ (lambda (msg &rest args)
+ (setq alert-called t)
+ (setq alert-message msg))))
+ (chime--notify "")
+ ;; Should still call alert, even with empty message
+ (should alert-called)
+ (should (equal alert-message ""))))
+ (test-chime-notify-teardown)))
+
+(ert-deftest test-chime-notify-no-sound-file-when-file-doesnt-exist ()
+ "Test that no sound is played when file doesn't exist."
+ (test-chime-notify-setup)
+ (unwind-protect
+ (let ((sound-played nil)
+ (alert-called nil))
+ (cl-letf* ((chime-play-sound t)
+ (chime-sound-file "/nonexistent/path/sound.wav")
+ ;; Mock file-exists-p to return nil
+ ((symbol-function 'file-exists-p) (lambda (file) nil))
+ ((symbol-function 'play-sound-file)
+ (lambda (file) (setq sound-played t)))
+ ((symbol-function 'alert)
+ (lambda (msg &rest args) (setq alert-called t))))
+ (chime--notify "Test Event")
+ ;; Should NOT play sound
+ (should-not sound-played)
+ ;; Should still show alert
+ (should alert-called)))
+ (test-chime-notify-teardown)))
+
+;;; Error Cases
+
+(ert-deftest test-chime-notify-handles-sound-playback-error-gracefully ()
+ "Test that errors in sound playback don't prevent notification."
+ (test-chime-notify-setup)
+ (unwind-protect
+ (let ((alert-called nil))
+ (cl-letf* ((chime-play-sound t)
+ (chime-sound-file "/some/file.wav")
+ ;; Mock file-exists-p to return t
+ ((symbol-function 'file-exists-p) (lambda (file) t))
+ ;; Mock play-sound-file to throw error
+ ((symbol-function 'play-sound-file)
+ (lambda (file) (error "Sound playback failed")))
+ ((symbol-function 'alert)
+ (lambda (msg &rest args) (setq alert-called t))))
+ ;; Should not throw error
+ (should-not (condition-case nil
+ (progn (chime--notify "Test Event") nil)
+ (error t)))
+ ;; Should still show alert despite sound error
+ (should alert-called)))
+ (test-chime-notify-teardown)))
+
+(ert-deftest test-chime-notify-handles-beep-error-gracefully ()
+ "Test that errors in beep don't prevent notification."
+ (test-chime-notify-setup)
+ (unwind-protect
+ (let ((alert-called nil))
+ (cl-letf* ((chime-play-sound t)
+ (chime-sound-file nil)
+ ;; Mock beep to throw error
+ ((symbol-function 'beep)
+ (lambda () (error "Beep failed")))
+ ((symbol-function 'alert)
+ (lambda (msg &rest args) (setq alert-called t))))
+ ;; Should not throw error
+ (should-not (condition-case nil
+ (progn (chime--notify "Test Event") nil)
+ (error t)))
+ ;; Should still show alert despite beep error
+ (should alert-called)))
+ (test-chime-notify-teardown)))
+
+(provide 'test-chime-notify)
+;;; test-chime-notify.el ends here
diff --git a/tests/test-chime-time-left.el b/tests/test-chime-time-left.el
new file mode 100644
index 0000000..c94801a
--- /dev/null
+++ b/tests/test-chime-time-left.el
@@ -0,0 +1,222 @@
+;;; test-chime-time-left.el --- Tests for chime--time-left -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2024 Craig Jennings
+
+;; Author: Craig Jennings <c@cjennings.net>
+
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Unit tests for chime--time-left function.
+;; Tests cover normal cases, boundary cases, and error cases.
+
+;;; Code:
+
+;; Initialize package system for batch mode
+(when noninteractive
+ (package-initialize))
+
+(require 'ert)
+
+;; Load dependencies required by chime
+(require 'dash)
+(require 'alert)
+(require 'async)
+(require 'org-agenda)
+
+;; Load chime from parent directory
+(load (expand-file-name "../chime.el") nil t)
+
+;; Load test utilities
+(require 'testutil-general (expand-file-name "testutil-general.el"))
+
+;;; Setup and Teardown
+
+(defun test-chime-time-left-setup ()
+ "Setup function run before each test."
+ (chime-create-test-base-dir))
+
+(defun test-chime-time-left-teardown ()
+ "Teardown function run after each test."
+ (chime-delete-test-base-dir))
+
+;;; Normal Cases
+
+(ert-deftest test-chime-time-left-one-minute-formats-correctly ()
+ "Test that 1 minute formats correctly."
+ (test-chime-time-left-setup)
+ (unwind-protect
+ (let ((result (chime--time-left 60)))
+ (should (stringp result))
+ (should (string-match-p "in 1 minute" result)))
+ (test-chime-time-left-teardown)))
+
+(ert-deftest test-chime-time-left-five-minutes-formats-correctly ()
+ "Test that 5 minutes formats correctly."
+ (test-chime-time-left-setup)
+ (unwind-protect
+ (let ((result (chime--time-left 300)))
+ (should (stringp result))
+ (should (string-match-p "in 5 minutes" result)))
+ (test-chime-time-left-teardown)))
+
+(ert-deftest test-chime-time-left-ten-minutes-formats-correctly ()
+ "Test that 10 minutes formats correctly."
+ (test-chime-time-left-setup)
+ (unwind-protect
+ (let ((result (chime--time-left 600)))
+ (should (stringp result))
+ (should (string-match-p "in 10 minutes" result)))
+ (test-chime-time-left-teardown)))
+
+(ert-deftest test-chime-time-left-thirty-minutes-formats-correctly ()
+ "Test that 30 minutes formats correctly."
+ (test-chime-time-left-setup)
+ (unwind-protect
+ (let ((result (chime--time-left 1800)))
+ (should (stringp result))
+ (should (string-match-p "in 30 minutes" result)))
+ (test-chime-time-left-teardown)))
+
+(ert-deftest test-chime-time-left-one-hour-formats-correctly ()
+ "Test that 1 hour formats correctly."
+ (test-chime-time-left-setup)
+ (unwind-protect
+ (let ((result (chime--time-left 3600)))
+ (should (stringp result))
+ ;; At exactly 1 hour (3600s), still shows minutes format
+ (should (string-match-p "in 60 minutes" result)))
+ (test-chime-time-left-teardown)))
+
+(ert-deftest test-chime-time-left-two-hours-formats-correctly ()
+ "Test that 2 hours formats correctly."
+ (test-chime-time-left-setup)
+ (unwind-protect
+ (let ((result (chime--time-left 7200)))
+ (should (stringp result))
+ (should (string-match-p "in 2 hours" result)))
+ (test-chime-time-left-teardown)))
+
+(ert-deftest test-chime-time-left-one-hour-thirty-minutes-formats-correctly ()
+ "Test that 1 hour 30 minutes formats correctly."
+ (test-chime-time-left-setup)
+ (unwind-protect
+ (let ((result (chime--time-left 5400)))
+ (should (stringp result))
+ ;; Should show both hours and minutes
+ (should (string-match-p "in 1 hour 30 minutes" result)))
+ (test-chime-time-left-teardown)))
+
+(ert-deftest test-chime-time-left-three-hours-fifteen-minutes-formats-correctly ()
+ "Test that 3 hours 15 minutes formats correctly."
+ (test-chime-time-left-setup)
+ (unwind-protect
+ (let ((result (chime--time-left 11700)))
+ (should (stringp result))
+ (should (string-match-p "in 3 hours 15 minutes" result)))
+ (test-chime-time-left-teardown)))
+
+;;; Boundary Cases
+
+(ert-deftest test-chime-time-left-zero-seconds-returns-right-now ()
+ "Test that 0 seconds returns 'right now'."
+ (test-chime-time-left-setup)
+ (unwind-protect
+ (let ((result (chime--time-left 0)))
+ (should (stringp result))
+ (should (string-equal "right now" result)))
+ (test-chime-time-left-teardown)))
+
+(ert-deftest test-chime-time-left-one-second-shows-right-now ()
+ "Test that 1 second shows 'right now'."
+ (test-chime-time-left-setup)
+ (unwind-protect
+ (let ((result (chime--time-left 1)))
+ (should (stringp result))
+ ;; Less than a minute, but format-seconds might show "in 0 minutes"
+ ;; or the implementation might handle this specially
+ (should result))
+ (test-chime-time-left-teardown)))
+
+(ert-deftest test-chime-time-left-fifty-nine-seconds-shows-minutes ()
+ "Test that 59 seconds shows in minutes format."
+ (test-chime-time-left-setup)
+ (unwind-protect
+ (let ((result (chime--time-left 59)))
+ (should (stringp result))
+ ;; Should use minutes format (< 1 hour)
+ (should (string-match-p "in" result)))
+ (test-chime-time-left-teardown)))
+
+(ert-deftest test-chime-time-left-exactly-one-hour-shows-minutes-format ()
+ "Test that exactly 1 hour shows minutes format."
+ (test-chime-time-left-setup)
+ (unwind-protect
+ (let ((result (chime--time-left 3600)))
+ (should (stringp result))
+ ;; At exactly 3600s, still uses minutes format (boundary case)
+ (should (string-match-p "in 60 minutes" result)))
+ (test-chime-time-left-teardown)))
+
+(ert-deftest test-chime-time-left-fifty-nine-minutes-shows-minutes-only ()
+ "Test that 59 minutes shows minutes format only."
+ (test-chime-time-left-setup)
+ (unwind-protect
+ (let ((result (chime--time-left 3540))) ; 59 minutes
+ (should (stringp result))
+ (should (string-match-p "in 59 minutes" result)))
+ (test-chime-time-left-teardown)))
+
+(ert-deftest test-chime-time-left-twenty-four-hours-formats-correctly ()
+ "Test that 24 hours formats correctly."
+ (test-chime-time-left-setup)
+ (unwind-protect
+ (let ((result (chime--time-left 86400)))
+ (should (stringp result))
+ (should (string-match-p "in 24 hours" result)))
+ (test-chime-time-left-teardown)))
+
+;;; Error Cases
+
+(ert-deftest test-chime-time-left-negative-value-returns-right-now ()
+ "Test that negative value returns 'right now'."
+ (test-chime-time-left-setup)
+ (unwind-protect
+ (let ((result (chime--time-left -60)))
+ (should (stringp result))
+ (should (string-equal "right now" result)))
+ (test-chime-time-left-teardown)))
+
+(ert-deftest test-chime-time-left-large-negative-returns-right-now ()
+ "Test that large negative value returns 'right now'."
+ (test-chime-time-left-setup)
+ (unwind-protect
+ (let ((result (chime--time-left -3600)))
+ (should (stringp result))
+ (should (string-equal "right now" result)))
+ (test-chime-time-left-teardown)))
+
+(ert-deftest test-chime-time-left-very-large-value-formats-correctly ()
+ "Test that very large value (1 week) formats correctly."
+ (test-chime-time-left-setup)
+ (unwind-protect
+ (let ((result (chime--time-left 604800))) ; 1 week
+ (should (stringp result))
+ ;; Should format with days/hours
+ (should (string-match-p "in" result)))
+ (test-chime-time-left-teardown)))
+
+(provide 'test-chime-time-left)
+;;; test-chime-time-left.el ends here
diff --git a/tests/test-chime-timestamp-parse.el b/tests/test-chime-timestamp-parse.el
new file mode 100644
index 0000000..c97806b
--- /dev/null
+++ b/tests/test-chime-timestamp-parse.el
@@ -0,0 +1,321 @@
+;;; test-chime-timestamp-parse.el --- Tests for chime--timestamp-parse -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2024 Craig Jennings
+
+;; Author: Craig Jennings <c@cjennings.net>
+
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Unit tests for chime--timestamp-parse function.
+;; Tests cover normal cases, boundary cases, and error cases.
+
+;;; Code:
+
+;; Initialize package system for batch mode
+(when noninteractive
+ (package-initialize))
+
+(require 'ert)
+
+;; Load dependencies required by chime
+(require 'dash)
+(require 'alert)
+(require 'async)
+(require 'org-agenda)
+
+;; Load chime from parent directory
+(load (expand-file-name "../chime.el") nil t)
+
+;; Load test utilities
+(require 'testutil-general (expand-file-name "testutil-general.el"))
+
+;;; Setup and Teardown
+
+(defun test-chime-timestamp-parse-setup ()
+ "Setup function run before each test."
+ (chime-create-test-base-dir))
+
+(defun test-chime-timestamp-parse-teardown ()
+ "Teardown function run after each test."
+ (chime-delete-test-base-dir))
+
+;;; Normal Cases
+
+(ert-deftest test-chime-timestamp-parse-standard-timestamp-returns-time-list ()
+ "Test that a standard timestamp with time component returns a time list."
+ (test-chime-timestamp-parse-setup)
+ (unwind-protect
+ (let* ((timestamp "<2025-10-24 Fri 14:30>")
+ (result (chime--timestamp-parse timestamp)))
+ ;; Should return a time list (list of integers)
+ (should (listp result))
+ (should (= (length result) 2))
+ (should (integerp (car result)))
+ (should (integerp (cadr result)))
+ ;; Result should not be nil
+ (should result))
+ (test-chime-timestamp-parse-teardown)))
+
+(ert-deftest test-chime-timestamp-parse-scheduled-timestamp-returns-time-list ()
+ "Test that a SCHEDULED timestamp parses correctly."
+ (test-chime-timestamp-parse-setup)
+ (unwind-protect
+ (let* ((timestamp "<2025-10-24 Fri 09:00>")
+ (result (chime--timestamp-parse timestamp)))
+ (should (listp result))
+ (should (= (length result) 2))
+ (should result))
+ (test-chime-timestamp-parse-teardown)))
+
+(ert-deftest test-chime-timestamp-parse-deadline-timestamp-returns-time-list ()
+ "Test that a DEADLINE timestamp parses correctly."
+ (test-chime-timestamp-parse-setup)
+ (unwind-protect
+ (let* ((timestamp "<2025-10-24 Fri 17:00>")
+ (result (chime--timestamp-parse timestamp)))
+ (should (listp result))
+ (should (= (length result) 2))
+ (should result))
+ (test-chime-timestamp-parse-teardown)))
+
+(ert-deftest test-chime-timestamp-parse-timestamp-with-weekly-repeater-returns-time-list ()
+ "Test that a timestamp with +1w repeater parses correctly."
+ (test-chime-timestamp-parse-setup)
+ (unwind-protect
+ (let* ((timestamp "<2025-10-24 Fri 14:00 +1w>")
+ (result (chime--timestamp-parse timestamp)))
+ (should (listp result))
+ (should (= (length result) 2))
+ (should result))
+ (test-chime-timestamp-parse-teardown)))
+
+(ert-deftest test-chime-timestamp-parse-timestamp-with-completion-repeater-returns-time-list ()
+ "Test that a timestamp with .+1d repeater parses correctly."
+ (test-chime-timestamp-parse-setup)
+ (unwind-protect
+ (let* ((timestamp "<2025-10-24 Fri 08:00 .+1d>")
+ (result (chime--timestamp-parse timestamp)))
+ (should (listp result))
+ (should (= (length result) 2))
+ (should result))
+ (test-chime-timestamp-parse-teardown)))
+
+(ert-deftest test-chime-timestamp-parse-timestamp-with-catchup-repeater-returns-time-list ()
+ "Test that a timestamp with ++1w repeater parses correctly."
+ (test-chime-timestamp-parse-setup)
+ (unwind-protect
+ (let* ((timestamp "<2025-10-24 Fri 10:30 ++1w>")
+ (result (chime--timestamp-parse timestamp)))
+ (should (listp result))
+ (should (= (length result) 2))
+ (should result))
+ (test-chime-timestamp-parse-teardown)))
+
+(ert-deftest test-chime-timestamp-parse-timestamp-with-time-range-returns-start-time ()
+ "Test that a timestamp with time range returns the start time."
+ (test-chime-timestamp-parse-setup)
+ (unwind-protect
+ (let* ((timestamp "<2025-10-24 Fri 14:00-15:30>")
+ (result (chime--timestamp-parse timestamp)))
+ (should (listp result))
+ (should (= (length result) 2))
+ (should result))
+ (test-chime-timestamp-parse-teardown)))
+
+(ert-deftest test-chime-timestamp-parse-timestamp-with-date-range-returns-start-date ()
+ "Test that a timestamp with date range returns start date time."
+ (test-chime-timestamp-parse-setup)
+ (unwind-protect
+ (let* ((timestamp "<2025-10-24 Fri 10:00>--<2025-10-25 Sat 10:00>")
+ (result (chime--timestamp-parse timestamp)))
+ (should (listp result))
+ (should (= (length result) 2))
+ (should result))
+ (test-chime-timestamp-parse-teardown)))
+
+;;; Boundary Cases
+
+(ert-deftest test-chime-timestamp-parse-midnight-timestamp-returns-time-list ()
+ "Test that midnight (00:00) timestamp parses correctly."
+ (test-chime-timestamp-parse-setup)
+ (unwind-protect
+ (let* ((timestamp "<2025-10-24 Fri 00:00>")
+ (result (chime--timestamp-parse timestamp)))
+ (should (listp result))
+ (should (= (length result) 2))
+ (should result))
+ (test-chime-timestamp-parse-teardown)))
+
+(ert-deftest test-chime-timestamp-parse-last-minute-of-day-returns-time-list ()
+ "Test that last minute of day (23:59) timestamp parses correctly."
+ (test-chime-timestamp-parse-setup)
+ (unwind-protect
+ (let* ((timestamp "<2025-10-24 Fri 23:59>")
+ (result (chime--timestamp-parse timestamp)))
+ (should (listp result))
+ (should (= (length result) 2))
+ (should result))
+ (test-chime-timestamp-parse-teardown)))
+
+(ert-deftest test-chime-timestamp-parse-year-boundary-new-years-eve-returns-time-list ()
+ "Test that New Year's Eve timestamp parses correctly."
+ (test-chime-timestamp-parse-setup)
+ (unwind-protect
+ (let* ((timestamp "<2025-12-31 Wed 23:30>")
+ (result (chime--timestamp-parse timestamp)))
+ (should (listp result))
+ (should (= (length result) 2))
+ (should result))
+ (test-chime-timestamp-parse-teardown)))
+
+(ert-deftest test-chime-timestamp-parse-year-boundary-new-years-day-returns-time-list ()
+ "Test that New Year's Day timestamp parses correctly."
+ (test-chime-timestamp-parse-setup)
+ (unwind-protect
+ (let* ((timestamp "<2026-01-01 Thu 00:30>")
+ (result (chime--timestamp-parse timestamp)))
+ (should (listp result))
+ (should (= (length result) 2))
+ (should result))
+ (test-chime-timestamp-parse-teardown)))
+
+(ert-deftest test-chime-timestamp-parse-single-digit-time-returns-time-list ()
+ "Test that single-digit hours and minutes parse correctly."
+ (test-chime-timestamp-parse-setup)
+ (unwind-protect
+ (let* ((timestamp "<2025-10-24 Fri 01:05>")
+ (result (chime--timestamp-parse timestamp)))
+ (should (listp result))
+ (should (= (length result) 2))
+ (should result))
+ (test-chime-timestamp-parse-teardown)))
+
+(ert-deftest test-chime-timestamp-parse-leap-year-feb-29-returns-time-list ()
+ "Test that Feb 29 in leap year parses correctly."
+ (test-chime-timestamp-parse-setup)
+ (unwind-protect
+ (let* ((timestamp "<2024-02-29 Thu 14:00>")
+ (result (chime--timestamp-parse timestamp)))
+ (should (listp result))
+ (should (= (length result) 2))
+ (should result))
+ (test-chime-timestamp-parse-teardown)))
+
+(ert-deftest test-chime-timestamp-parse-month-boundary-end-of-month-returns-time-list ()
+ "Test that end of month timestamp parses correctly."
+ (test-chime-timestamp-parse-setup)
+ (unwind-protect
+ (let* ((timestamp "<2025-10-31 Fri 14:00>")
+ (result (chime--timestamp-parse timestamp)))
+ (should (listp result))
+ (should (= (length result) 2))
+ (should result))
+ (test-chime-timestamp-parse-teardown)))
+
+;;; Error Cases
+
+(ert-deftest test-chime-timestamp-parse-empty-string-returns-nil ()
+ "Test that empty string returns nil."
+ (test-chime-timestamp-parse-setup)
+ (unwind-protect
+ (let* ((timestamp "")
+ (result (chime--timestamp-parse timestamp)))
+ (should (null result)))
+ (test-chime-timestamp-parse-teardown)))
+
+(ert-deftest test-chime-timestamp-parse-nil-input-returns-nil ()
+ "Test that nil input returns nil."
+ (test-chime-timestamp-parse-setup)
+ (unwind-protect
+ (let* ((timestamp nil)
+ (result (chime--timestamp-parse timestamp)))
+ (should (null result)))
+ (test-chime-timestamp-parse-teardown)))
+
+(ert-deftest test-chime-timestamp-parse-missing-opening-bracket-returns-nil ()
+ "Test that timestamp missing opening bracket returns nil."
+ (test-chime-timestamp-parse-setup)
+ (unwind-protect
+ (let* ((timestamp "2025-10-24 Fri 14:00>")
+ (result (chime--timestamp-parse timestamp)))
+ (should (null result)))
+ (test-chime-timestamp-parse-teardown)))
+
+(ert-deftest test-chime-timestamp-parse-missing-closing-bracket-returns-nil ()
+ "Test that timestamp missing closing bracket returns nil."
+ (test-chime-timestamp-parse-setup)
+ (unwind-protect
+ (let* ((timestamp "<2025-10-24 Fri 14:00")
+ (result (chime--timestamp-parse timestamp)))
+ (should (null result)))
+ (test-chime-timestamp-parse-teardown)))
+
+(ert-deftest test-chime-timestamp-parse-invalid-date-format-returns-nil ()
+ "Test that invalid date format returns nil."
+ (test-chime-timestamp-parse-setup)
+ (unwind-protect
+ (let* ((timestamp "<10-24-2025 Fri 14:00>")
+ (result (chime--timestamp-parse timestamp)))
+ (should (null result)))
+ (test-chime-timestamp-parse-teardown)))
+
+(ert-deftest test-chime-timestamp-parse-invalid-month-returns-nil ()
+ "Test that invalid month value returns nil."
+ (test-chime-timestamp-parse-setup)
+ (unwind-protect
+ (let* ((timestamp "<2025-13-24 Fri 14:00>")
+ (result (chime--timestamp-parse timestamp)))
+ (should (null result)))
+ (test-chime-timestamp-parse-teardown)))
+
+(ert-deftest test-chime-timestamp-parse-invalid-day-returns-nil ()
+ "Test that invalid day value returns nil."
+ (test-chime-timestamp-parse-setup)
+ (unwind-protect
+ (let* ((timestamp "<2025-10-32 Fri 14:00>")
+ (result (chime--timestamp-parse timestamp)))
+ (should (null result)))
+ (test-chime-timestamp-parse-teardown)))
+
+(ert-deftest test-chime-timestamp-parse-invalid-time-hour-returns-nil ()
+ "Test that invalid hour value returns nil."
+ (test-chime-timestamp-parse-setup)
+ (unwind-protect
+ (let* ((timestamp "<2025-10-24 Fri 25:00>")
+ (result (chime--timestamp-parse timestamp)))
+ (should (null result)))
+ (test-chime-timestamp-parse-teardown)))
+
+(ert-deftest test-chime-timestamp-parse-invalid-time-minute-returns-nil ()
+ "Test that invalid minute value returns nil."
+ (test-chime-timestamp-parse-setup)
+ (unwind-protect
+ (let* ((timestamp "<2025-10-24 Fri 14:60>")
+ (result (chime--timestamp-parse timestamp)))
+ (should (null result)))
+ (test-chime-timestamp-parse-teardown)))
+
+(ert-deftest test-chime-timestamp-parse-date-only-no-time-returns-nil ()
+ "Test that day-wide timestamp without time returns nil."
+ (test-chime-timestamp-parse-setup)
+ (unwind-protect
+ (let* ((timestamp "<2025-10-24 Fri>")
+ (result (chime--timestamp-parse timestamp)))
+ (should (null result)))
+ (test-chime-timestamp-parse-teardown)))
+
+(provide 'test-chime-timestamp-parse)
+;;; test-chime-timestamp-parse.el ends here
diff --git a/tests/test-chime-timestamp-within-interval-p.el b/tests/test-chime-timestamp-within-interval-p.el
new file mode 100644
index 0000000..89b8056
--- /dev/null
+++ b/tests/test-chime-timestamp-within-interval-p.el
@@ -0,0 +1,280 @@
+;;; test-chime-timestamp-within-interval-p.el --- Tests for chime--timestamp-within-interval-p -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2024 Craig Jennings
+
+;; Author: Craig Jennings <c@cjennings.net>
+
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Unit tests for chime--timestamp-within-interval-p function.
+;; Tests cover normal cases, boundary cases, and error cases.
+
+;;; Code:
+
+;; Initialize package system for batch mode
+(when noninteractive
+ (package-initialize))
+
+(require 'ert)
+
+;; Load dependencies required by chime
+(require 'dash)
+(require 'alert)
+(require 'async)
+(require 'org-agenda)
+
+;; Load chime from parent directory
+(load (expand-file-name "../chime.el") nil t)
+
+;; Load test utilities
+(require 'testutil-general (expand-file-name "testutil-general.el"))
+
+;;; Setup and Teardown
+
+(defun test-chime-timestamp-within-interval-p-setup ()
+ "Setup function run before each test."
+ (chime-create-test-base-dir))
+
+(defun test-chime-timestamp-within-interval-p-teardown ()
+ "Teardown function run after each test."
+ (chime-delete-test-base-dir))
+
+;;; Normal Cases
+
+(ert-deftest test-chime-timestamp-within-interval-p-exactly-at-interval-returns-t ()
+ "Test that timestamp exactly at interval returns t."
+ (test-chime-timestamp-within-interval-p-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ ;; Timestamp at 14:10 (10 minutes from 14:00)
+ (timestamp (encode-time 0 10 14 24 10 2025))
+ (interval 10)
+ (result (chime--timestamp-within-interval-p timestamp interval)))
+ (should result))
+ (test-chime-timestamp-within-interval-p-teardown)))
+
+(ert-deftest test-chime-timestamp-within-interval-p-zero-interval-returns-t ()
+ "Test that zero interval (notify now) returns t for current time."
+ (test-chime-timestamp-within-interval-p-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 30 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ ;; Timestamp at exactly current time (14:30)
+ (timestamp (encode-time 0 30 14 24 10 2025))
+ (interval 0)
+ (result (chime--timestamp-within-interval-p timestamp interval)))
+ (should result))
+ (test-chime-timestamp-within-interval-p-teardown)))
+
+(ert-deftest test-chime-timestamp-within-interval-p-five-minutes-returns-t ()
+ "Test that 5-minute interval works correctly."
+ (test-chime-timestamp-within-interval-p-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 25 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ ;; Timestamp at 14:30 (5 minutes from 14:25)
+ (timestamp (encode-time 0 30 14 24 10 2025))
+ (interval 5)
+ (result (chime--timestamp-within-interval-p timestamp interval)))
+ (should result))
+ (test-chime-timestamp-within-interval-p-teardown)))
+
+(ert-deftest test-chime-timestamp-within-interval-p-sixty-minutes-returns-t ()
+ "Test that 60-minute (1 hour) interval works correctly."
+ (test-chime-timestamp-within-interval-p-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ ;; Timestamp at 15:00 (60 minutes from 14:00)
+ (timestamp (encode-time 0 0 15 24 10 2025))
+ (interval 60)
+ (result (chime--timestamp-within-interval-p timestamp interval)))
+ (should result))
+ (test-chime-timestamp-within-interval-p-teardown)))
+
+(ert-deftest test-chime-timestamp-within-interval-p-large-interval-returns-t ()
+ "Test that large interval (1 day = 1440 minutes) works correctly."
+ (test-chime-timestamp-within-interval-p-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ ;; Timestamp at 14:00 next day (1440 minutes from now)
+ (timestamp (encode-time 0 0 14 25 10 2025))
+ (interval 1440)
+ (result (chime--timestamp-within-interval-p timestamp interval)))
+ (should result))
+ (test-chime-timestamp-within-interval-p-teardown)))
+
+(ert-deftest test-chime-timestamp-within-interval-p-thirty-minutes-returns-t ()
+ "Test that 30-minute interval works correctly."
+ (test-chime-timestamp-within-interval-p-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 15 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ ;; Timestamp at 14:45 (30 minutes from 14:15)
+ (timestamp (encode-time 0 45 14 24 10 2025))
+ (interval 30)
+ (result (chime--timestamp-within-interval-p timestamp interval)))
+ (should result))
+ (test-chime-timestamp-within-interval-p-teardown)))
+
+;;; Boundary Cases
+
+(ert-deftest test-chime-timestamp-within-interval-p-one-minute-before-returns-nil ()
+ "Test that timestamp 1 minute before interval returns nil."
+ (test-chime-timestamp-within-interval-p-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ ;; Timestamp at 14:09 (9 minutes from 14:00, not 10)
+ (timestamp (encode-time 0 9 14 24 10 2025))
+ (interval 10)
+ (result (chime--timestamp-within-interval-p timestamp interval)))
+ (should-not result))
+ (test-chime-timestamp-within-interval-p-teardown)))
+
+(ert-deftest test-chime-timestamp-within-interval-p-one-minute-after-returns-nil ()
+ "Test that timestamp 1 minute after interval returns nil."
+ (test-chime-timestamp-within-interval-p-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ ;; Timestamp at 14:11 (11 minutes from 14:00, not 10)
+ (timestamp (encode-time 0 11 14 24 10 2025))
+ (interval 10)
+ (result (chime--timestamp-within-interval-p timestamp interval)))
+ (should-not result))
+ (test-chime-timestamp-within-interval-p-teardown)))
+
+(ert-deftest test-chime-timestamp-within-interval-p-crossing-midnight-returns-t ()
+ "Test that interval crossing midnight works correctly."
+ (test-chime-timestamp-within-interval-p-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 50 23 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ ;; Timestamp at 00:00 next day (10 minutes from 23:50)
+ (timestamp (encode-time 0 0 0 25 10 2025))
+ (interval 10)
+ (result (chime--timestamp-within-interval-p timestamp interval)))
+ (should result))
+ (test-chime-timestamp-within-interval-p-teardown)))
+
+(ert-deftest test-chime-timestamp-within-interval-p-crossing-day-boundary-returns-t ()
+ "Test that interval crossing to next day works correctly."
+ (test-chime-timestamp-within-interval-p-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 30 23 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ ;; Timestamp at 00:30 next day (60 minutes from 23:30)
+ (timestamp (encode-time 0 30 0 25 10 2025))
+ (interval 60)
+ (result (chime--timestamp-within-interval-p timestamp interval)))
+ (should result))
+ (test-chime-timestamp-within-interval-p-teardown)))
+
+(ert-deftest test-chime-timestamp-within-interval-p-week-interval-returns-t ()
+ "Test that very large interval (1 week = 10080 minutes) works."
+ (test-chime-timestamp-within-interval-p-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ ;; Timestamp at 14:00 one week later
+ (timestamp (encode-time 0 0 14 31 10 2025))
+ (interval 10080)
+ (result (chime--timestamp-within-interval-p timestamp interval)))
+ (should result))
+ (test-chime-timestamp-within-interval-p-teardown)))
+
+(ert-deftest test-chime-timestamp-within-interval-p-at-midnight-returns-t ()
+ "Test that timestamp at exact midnight works correctly."
+ (test-chime-timestamp-within-interval-p-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 50 23 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ ;; Timestamp at midnight (10 minutes from 23:50)
+ (timestamp (encode-time 0 0 0 25 10 2025))
+ (interval 10)
+ (result (chime--timestamp-within-interval-p timestamp interval)))
+ (should result))
+ (test-chime-timestamp-within-interval-p-teardown)))
+
+;;; Error Cases
+
+(ert-deftest test-chime-timestamp-within-interval-p-nil-timestamp-returns-nil ()
+ "Test that nil timestamp returns nil."
+ (test-chime-timestamp-within-interval-p-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ (timestamp nil)
+ (interval 10)
+ (result (chime--timestamp-within-interval-p timestamp interval)))
+ (should-not result))
+ (test-chime-timestamp-within-interval-p-teardown)))
+
+(ert-deftest test-chime-timestamp-within-interval-p-nil-interval-returns-nil ()
+ "Test that nil interval returns nil."
+ (test-chime-timestamp-within-interval-p-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ (timestamp (encode-time 0 10 14 24 10 2025))
+ (interval nil)
+ (result (chime--timestamp-within-interval-p timestamp interval)))
+ (should-not result))
+ (test-chime-timestamp-within-interval-p-teardown)))
+
+(ert-deftest test-chime-timestamp-within-interval-p-negative-interval-returns-nil ()
+ "Test that negative interval returns nil (past timestamps)."
+ (test-chime-timestamp-within-interval-p-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ ;; Timestamp 10 minutes in the past (13:50)
+ (timestamp (encode-time 0 50 13 24 10 2025))
+ (interval -10)
+ (result (chime--timestamp-within-interval-p timestamp interval)))
+ (should result))
+ (test-chime-timestamp-within-interval-p-teardown)))
+
+(ert-deftest test-chime-timestamp-within-interval-p-invalid-timestamp-returns-nil ()
+ "Test that invalid timestamp format returns nil."
+ (test-chime-timestamp-within-interval-p-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ (timestamp "not-a-timestamp")
+ (interval 10)
+ (result (chime--timestamp-within-interval-p timestamp interval)))
+ (should-not result))
+ (test-chime-timestamp-within-interval-p-teardown)))
+
+(ert-deftest test-chime-timestamp-within-interval-p-float-interval-works ()
+ "Test that float interval gets converted properly."
+ (test-chime-timestamp-within-interval-p-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ ;; Timestamp at 14:10 (10 minutes from 14:00)
+ (timestamp (encode-time 0 10 14 24 10 2025))
+ (interval 10.5)
+ (result (chime--timestamp-within-interval-p timestamp interval)))
+ (should result))
+ (test-chime-timestamp-within-interval-p-teardown)))
+
+(provide 'test-chime-timestamp-within-interval-p)
+;;; test-chime-timestamp-within-interval-p.el ends here
diff --git a/tests/test-chime-update-modeline.el b/tests/test-chime-update-modeline.el
new file mode 100644
index 0000000..c2a5f54
--- /dev/null
+++ b/tests/test-chime-update-modeline.el
@@ -0,0 +1,204 @@
+;;; test-chime-update-modeline.el --- Tests for chime--update-modeline -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2024 Craig Jennings
+
+;; Author: Craig Jennings <c@cjennings.net>
+
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Unit tests for chime--update-modeline function.
+;; Tests cover normal cases, boundary cases, and error cases.
+
+;;; Code:
+
+;; Initialize package system for batch mode
+(when noninteractive
+ (package-initialize))
+
+(require 'ert)
+
+;; Load dependencies required by chime
+(require 'dash)
+(require 'alert)
+(require 'async)
+(require 'org-agenda)
+
+;; Load chime from parent directory
+(load (expand-file-name "../chime.el") nil t)
+
+;; Load test utilities
+(require 'testutil-general (expand-file-name "testutil-general.el"))
+
+;;; Setup and Teardown
+
+(defun test-chime-update-modeline-setup ()
+ "Setup function run before each test."
+ (chime-create-test-base-dir)
+ ;; Reset modeline settings
+ (setq chime-modeline-string nil)
+ (setq chime-modeline-lookahead 30)
+ (setq chime-modeline-format " ⏰ %s"))
+
+(defun test-chime-update-modeline-teardown ()
+ "Teardown function run after each test."
+ (chime-delete-test-base-dir)
+ (setq chime-modeline-string nil))
+
+;;; Normal Cases
+
+(ert-deftest test-chime-update-modeline-single-event-within-window-updates-modeline ()
+ "Test that single event within lookahead window updates modeline."
+ (test-chime-update-modeline-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ ((symbol-function 'force-mode-line-update) (lambda ()))
+ ;; Event at 14:10 (10 minutes from now)
+ (event-time (encode-time 0 10 14 24 10 2025))
+ (event `((times . ((("<2025-10-24 Fri 14:10>" . ,event-time))))
+ (title . "Team Meeting")))
+ (events (list event)))
+ (chime--update-modeline events)
+ ;; Should set modeline string
+ (should chime-modeline-string)
+ (should (stringp chime-modeline-string))
+ (should (string-match-p "Team Meeting" chime-modeline-string))
+ (should (string-match-p "10 minutes" chime-modeline-string)))
+ (test-chime-update-modeline-teardown)))
+
+(ert-deftest test-chime-update-modeline-multiple-events-picks-soonest ()
+ "Test that with multiple events, soonest one is shown."
+ (test-chime-update-modeline-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ ((symbol-function 'force-mode-line-update) (lambda ()))
+ ;; Event 1 at 14:05 (5 minutes - soonest)
+ (event-time-1 (encode-time 0 5 14 24 10 2025))
+ (event1 `((times . ((("<2025-10-24 Fri 14:05>" . ,event-time-1))))
+ (title . "Standup")))
+ ;; Event 2 at 14:25 (25 minutes)
+ (event-time-2 (encode-time 0 25 14 24 10 2025))
+ (event2 `((times . ((("<2025-10-24 Fri 14:25>" . ,event-time-2))))
+ (title . "Code Review")))
+ (events (list event1 event2)))
+ (chime--update-modeline events)
+ ;; Should show the soonest event
+ (should chime-modeline-string)
+ (should (string-match-p "Standup" chime-modeline-string))
+ (should-not (string-match-p "Code Review" chime-modeline-string)))
+ (test-chime-update-modeline-teardown)))
+
+(ert-deftest test-chime-update-modeline-event-outside-window-no-update ()
+ "Test that event outside lookahead window doesn't update modeline."
+ (test-chime-update-modeline-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ ((symbol-function 'force-mode-line-update) (lambda ()))
+ ;; Event at 15:10 (70 minutes from now, outside 30 minute window)
+ (event-time (encode-time 0 10 15 24 10 2025))
+ (event `((times . ((("<2025-10-24 Fri 15:10>" . ,event-time))))
+ (title . "Far Future Event")))
+ (events (list event)))
+ (chime--update-modeline events)
+ ;; Should NOT set modeline string
+ (should-not chime-modeline-string))
+ (test-chime-update-modeline-teardown)))
+
+(ert-deftest test-chime-update-modeline-zero-lookahead-clears-modeline ()
+ "Test that zero lookahead clears modeline."
+ (test-chime-update-modeline-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ ((symbol-function 'force-mode-line-update) (lambda ()))
+ (event-time (encode-time 0 10 14 24 10 2025))
+ (event `((times . ((("<2025-10-24 Fri 14:10>" . ,event-time))))
+ (title . "Team Meeting")))
+ (events (list event)))
+ (setq chime-modeline-lookahead 0)
+ (chime--update-modeline events)
+ ;; Should clear modeline
+ (should-not chime-modeline-string))
+ (test-chime-update-modeline-teardown)))
+
+;;; Boundary Cases
+
+(ert-deftest test-chime-update-modeline-no-events-clears-modeline ()
+ "Test that no events clears modeline."
+ (test-chime-update-modeline-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ ((symbol-function 'force-mode-line-update) (lambda ()))
+ (events '()))
+ (chime--update-modeline events)
+ (should-not chime-modeline-string))
+ (test-chime-update-modeline-teardown)))
+
+(ert-deftest test-chime-update-modeline-day-wide-events-filtered-out ()
+ "Test that day-wide events are filtered out."
+ (test-chime-update-modeline-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ ((symbol-function 'force-mode-line-update) (lambda ()))
+ (event-time (encode-time 0 0 0 24 10 2025))
+ (event `((times . ((("<2025-10-24 Fri>" . ,event-time))))
+ (title . "All Day Event")))
+ (events (list event)))
+ (chime--update-modeline events)
+ (should-not chime-modeline-string))
+ (test-chime-update-modeline-teardown)))
+
+(ert-deftest test-chime-update-modeline-event-at-exact-boundary-included ()
+ "Test that event at exact lookahead boundary is included."
+ (test-chime-update-modeline-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ ((symbol-function 'force-mode-line-update) (lambda ()))
+ ;; Event at 14:30 (exactly 30 minutes, at boundary)
+ (event-time (encode-time 0 30 14 24 10 2025))
+ (event `((times . ((("<2025-10-24 Fri 14:30>" . ,event-time))))
+ (title . "Boundary Event")))
+ (events (list event)))
+ (chime--update-modeline events)
+ (should chime-modeline-string)
+ (should (string-match-p "Boundary Event" chime-modeline-string)))
+ (test-chime-update-modeline-teardown)))
+
+;;; Error Cases
+
+(ert-deftest test-chime-update-modeline-past-events-not-shown ()
+ "Test that past events are not shown in modeline."
+ (test-chime-update-modeline-setup)
+ (unwind-protect
+ (cl-letf* ((mock-time (encode-time 0 0 14 24 10 2025))
+ ((symbol-function 'current-time) (lambda () mock-time))
+ ((symbol-function 'force-mode-line-update) (lambda ()))
+ ;; Event at 13:50 (10 minutes ago)
+ (event-time (encode-time 0 50 13 24 10 2025))
+ (event `((times . ((("<2025-10-24 Fri 13:50>" . ,event-time))))
+ (title . "Past Event")))
+ (events (list event)))
+ (chime--update-modeline events)
+ (should-not chime-modeline-string))
+ (test-chime-update-modeline-teardown)))
+
+(provide 'test-chime-update-modeline)
+;;; test-chime-update-modeline.el ends here
diff --git a/tests/testing-strategy.org b/tests/testing-strategy.org
new file mode 100644
index 0000000..d7b25a9
--- /dev/null
+++ b/tests/testing-strategy.org
@@ -0,0 +1,319 @@
+#+TITLE: CHIME Testing Strategy
+#+AUTHOR: Craig Jennings
+#+DATE: 2024-10-24
+
+* Overview
+
+This document outlines the ERT test strategy for the CHIME package, prioritizing critical functionality and documenting what should be tested and why.
+
+* Test Guidelines
+
+** Requirements
+- All tests in =chime.el/tests/= directory
+- File naming: =test-chime-<methodname>.el=
+- Use =testutil-general.el= utilities for test data management
+- Tests must be independent, deterministic, and isolated
+
+** Testing Approach
+- ERT framework
+- Each test verifies one specific behavior
+- Mock external dependencies (file I/O, time, network)
+- Descriptive naming: =test-chime-<function>-<scenario>-<expected-result>=
+
+** CHIME-Specific Considerations
+- Mock: =alert=, =play-sound-file=, =current-time=, async operations, org-agenda functions
+- Focus on critical paths: notification logic, modeline updates, sound playback, time calculations
+
+* Priority Tiers
+
+** TIER 1: Core Logic (Must Test)
+
+*** DONE Test chime--timestamp-parse
+:PROPERTIES:
+:PRIORITY: A
+:TIER: 1
+:END:
+
+*Why:* Fixed bugs here. Converts org timestamps to Emacs time. Foundation of all time calculations.
+
+*Risk:*
+- Malformed timestamps
+- Timezone issues
+- Repeating timestamps (=+1w=, =.+1d=, =++1w=)
+- Edge cases around midnight
+- Invalid date/time strings
+
+*Test Coverage:*
+- Normal: Valid timestamps with various formats
+- Boundary: Midnight, year boundaries, DST transitions
+- Error: Malformed strings, missing components, invalid dates
+
+*Status:* ✅ Complete - 25 tests, all passing
+
+*** DONE Test chime--has-timestamp
+:PROPERTIES:
+:PRIORITY: A
+:TIER: 1
+:END:
+
+*Why:* Fixed bugs here. Determines if event has valid time component. Gates whether events get processed.
+
+*Risk:*
+- Misclassifying day-wide vs timed events
+- False positives/negatives on timestamp detection
+- Not handling all org timestamp formats
+
+*Test Coverage:*
+- Normal: Standard timestamps with time components
+- Boundary: Timestamps at boundaries, with/without time
+- Error: Invalid formats, missing brackets, partial timestamps
+
+*Status:* ✅ Complete - 17 tests, all passing
+
+*** DONE Test chime--timestamp-within-interval-p
+:PROPERTIES:
+:PRIORITY: A
+:TIER: 1
+:END:
+
+*Why:* The "should we notify NOW?" decision. Critical timing logic.
+
+*Risk:*
+- Off-by-one errors
+- Boundary conditions around notification times
+- Incorrect interval calculations
+- Missing notifications at exact times
+
+*Test Coverage:*
+- Normal: Events at various intervals (5 min, 1 hour, etc.)
+- Boundary: Exactly at notification time, 0 minutes, very large intervals
+- Error: Negative intervals, past events, invalid timestamps
+
+*Status:* ✅ Complete - 17 tests, all passing
+
+*** DONE Test chime--notifications
+:PROPERTIES:
+:PRIORITY: A
+:TIER: 1
+:END:
+
+*Why:* Calculates which notifications should fire for an event. Combines alert times with event times.
+
+*Risk:*
+- Missing notifications
+- Duplicate notifications
+- Incorrect intervals
+- Not respecting per-event CHIME_NOTIFY_BEFORE property
+- Wrong interaction between global and per-event settings
+
+*Test Coverage:*
+- Normal: Single alert time, multiple alert times, per-event overrides
+- Boundary: Alert at event time (0 minutes), very early alerts
+- Error: Invalid alert times, missing properties, conflicting settings
+
+*Status:* ✅ Complete - 10 tests, all passing, no bugs found
+
+*** DONE Test chime--check-event
+:PROPERTIES:
+:PRIORITY: A
+:TIER: 1
+:END:
+
+*Why:* Processes single event and returns notification list. Main business logic.
+
+*Risk:*
+- Logic errors combining filtering and time checks
+- Missing edge cases in event processing
+- Incorrect event data extraction
+- Filtering interactions
+
+*Test Coverage:*
+- Normal: Valid events with various configurations
+- Boundary: Events at exact notification time, multiple timestamps
+- Error: Malformed events, missing required fields
+
+*Status:* ✅ Complete - 7 tests, all passing, no bugs found
+
+** TIER 2: Key Features (Should Test)
+
+*** DONE Test chime--update-modeline
+:PROPERTIES:
+:PRIORITY: B
+:TIER: 2
+:END:
+
+*Why:* New feature. Calculates soonest event within lookahead window.
+
+*Risk:*
+- Wrong event shown
+- Returns nil when should show event
+- Not updating when events change
+- Lookahead window calculation errors
+- Format string issues
+
+*Test Coverage:*
+- Normal: Single event, multiple events, events outside window
+- Boundary: Event exactly at lookahead boundary, 0 lookahead
+- Error: No events, all events outside window, malformed events
+
+*Status:* ✅ Complete - 8 tests, all passing, no bugs found
+
+*** DONE Test chime--notify
+:PROPERTIES:
+:PRIORITY: B
+:TIER: 2
+:END:
+
+*Why:* Actually sends notifications and plays sound. User-facing.
+
+*Risk:*
+- Sound file not found
+- Sound file corrupted
+- Notification failures
+- Error handling doesn't prevent notification display
+
+*Test Coverage:*
+- Normal: Valid sound file, notification with sound enabled
+- Boundary: Sound disabled, custom sound file
+- Error: Missing sound file, invalid file path, permission errors
+
+*Status:* ✅ Complete - 8 tests, all passing, no bugs found
+
+*** DONE Test chime--notification-text
+:PROPERTIES:
+:PRIORITY: B
+:TIER: 2
+:END:
+
+*Why:* Formats notification messages. User sees this directly.
+
+*Risk:*
+- Formatting errors
+- Edge cases in time display
+- Unicode/special character handling
+- Very long event titles
+
+*Test Coverage:*
+- Normal: Standard event with title and time
+- Boundary: Very long titles, titles with special chars, minimal data
+- Error: Missing event data, malformed time intervals
+
+*Status:* ✅ Complete - 11 tests, all passing, no bugs found
+
+*** DONE Test chime--time-left
+:PROPERTIES:
+:PRIORITY: B
+:TIER: 2
+:END:
+
+*Why:* Formats "in X minutes/hours" text. User-visible.
+
+*Risk:*
+- Plural/singular errors
+- Formatting edge cases (0 minutes, "right now")
+- Very large time values
+- Negative times
+
+*Test Coverage:*
+- Normal: Various time intervals (seconds, minutes, hours, days)
+- Boundary: 0 seconds, 1 minute, 60 minutes, 24 hours
+- Error: Negative times, extremely large values
+
+*Status:* ✅ Complete - 17 tests, all passing, no bugs found
+
+** TIER 3: Filtering (Good to Test)
+
+*** DONE Test chime--apply-whitelist
+:PROPERTIES:
+:PRIORITY: C
+:TIER: 3
+:END:
+
+*Why:* Filters events by keyword/tag whitelist.
+
+*Risk:*
+- Filtering out valid events
+- Letting through invalid events
+- Interaction between keyword and tag filters
+
+*Test Coverage:*
+- Normal: Valid whitelist with matching/non-matching events
+- Boundary: Empty whitelist (nil), single item, many items
+- Error: Invalid whitelist format, malformed events
+
+*Status:* ✅ Complete - 9 tests, all passing, no bugs found
+
+*** DONE Test chime--apply-blacklist
+:PROPERTIES:
+:PRIORITY: C
+:TIER: 3
+:END:
+
+*Why:* Filters events by keyword/tag blacklist.
+
+*Risk:*
+- Filtering out valid events
+- Letting through invalid events
+- Interaction with whitelist
+
+*Test Coverage:*
+- Normal: Valid blacklist with matching/non-matching events
+- Boundary: Empty blacklist, single item, many items
+- Error: Invalid blacklist format, malformed events
+
+*Status:* ✅ Complete - 10 tests, all passing, no bugs found
+
+*** DONE Test chime--extract-time
+:PROPERTIES:
+:PRIORITY: C
+:TIER: 3
+:END:
+
+*Why:* Extracts SCHEDULED/DEADLINE/timestamp from org entry.
+
+*Risk:*
+- Missing timestamps
+- Wrong priority (SCHEDULED vs DEADLINE vs plain)
+- Not handling multiple timestamps correctly
+
+*Test Coverage:*
+- Normal: Events with SCHEDULED, DEADLINE, plain timestamps
+- Boundary: Multiple timestamps, conflicting times
+- Error: No timestamps, malformed org entries
+
+*Status:* ✅ Complete - 12 tests, all passing, no bugs found
+
+* Methods Skipped
+
+These methods are either trivial, covered by higher-level tests, or difficult to unit test meaningfully.
+
+** SKIP chime--extract-title
+*Reason:* Simple text extraction from org entry. Covered by integration tests. Low risk.
+
+** SKIP chime--gather-info
+*Reason:* Simple aggregator function that calls other functions. Testing the individual functions provides sufficient coverage.
+
+** SKIP chime--get-tags
+*Reason:* Trivial property getter. One-liner wrapper around org-entry-get.
+
+** SKIP chime--time=
+*Reason:* Trivial time comparison helper. Low complexity, low risk.
+
+** SKIP chime--today
+*Reason:* Simple wrapper around time-to-days. Trivial.
+
+** SKIP chime--retrieve-events
+*Reason:* Complex org-agenda integration using async. Very difficult to unit test. Better tested via integration tests.
+
+** SKIP chime--check-events
+*Reason:* Already well-covered by existing integration tests (chime-tests.el). Orchestration function that calls testable components.
+
+** SKIP Day-wide event functions
+*Functions:* =chime-current-time-is-day-wide-time=, =chime-day-wide-notifications=, =chime-display-as-day-wide-event=, =chime-event-has-any-day-wide-timestamp=, =chime-event-has-any-passed-time=, =chime--day-wide-notification-text=
+
+*Reason:* Edge case functionality with lower priority. Existing integration tests provide some coverage.
+
+** SKIP Mode management functions
+*Functions:* =chime-mode=, =chime--start=, =chime--stop=, =chime-check=
+
+*Reason:* Integration test territory. Requires full Emacs environment. Difficult to meaningfully unit test.
diff --git a/tests/testutil-general.el b/tests/testutil-general.el
new file mode 100644
index 0000000..556e520
--- /dev/null
+++ b/tests/testutil-general.el
@@ -0,0 +1,184 @@
+;;; testutil-general.el --- -*- coding: utf-8; lexical-binding: t; -*-
+;;
+;; Author: Craig Jennings <c@cjennings.net>
+;;
+;;; Commentary:
+;; This library provides general helper functions and constants for managing
+;; test directories and files across test suites.
+;;
+;; It establishes a user-local hidden directory as the root for all test assets,
+;; provides utilities to create this directory safely, create temporary files
+;; and subdirectories within it, and clean up after tests.
+;;
+;; This library should be required by test suites to ensure consistent,
+;; reliable, and isolated file-system resources.
+;;
+;;; Code:
+
+(defconst chime-test-base-dir
+ (expand-file-name "~/.temp-chime-tests/")
+ "Base directory for all CHIME test files and directories.
+All test file-system artifacts should be created under this hidden
+directory in the user's home. This avoids relying on ephemeral system
+directories like /tmp and reduces flaky test failures caused by external
+cleanup.")
+
+(defun chime-create-test-base-dir ()
+ "Create the test base directory `chime-test-base-dir' if it does not exist.
+Returns the absolute path to the test base directory.
+Signals an error if creation fails."
+ (let ((dir (file-name-as-directory chime-test-base-dir)))
+ (unless (file-directory-p dir)
+ (make-directory dir t))
+ (if (file-directory-p dir) dir
+ (error "Failed to create test base directory %s" dir))))
+
+(defun chime-create--directory-ensuring-parents (dirpath)
+ "Create nested directories specified by DIRPATH.
+Error if DIRPATH exists already.
+Ensure DIRPATH is within `chime-test-base-dir`."
+ (let* ((base (file-name-as-directory chime-test-base-dir))
+ (fullpath (expand-file-name dirpath base)))
+ (unless (string-prefix-p base fullpath)
+ (error "Directory path %s is outside base test directory %s" fullpath base))
+ (when (file-exists-p fullpath)
+ (error "Directory path already exists: %s" fullpath))
+ (make-directory fullpath t)
+ fullpath))
+
+(defun chime-create--file-ensuring-parents (filepath content &optional executable)
+ "Create file at FILEPATH (relative to `chime-test-base-dir`) with CONTENT.
+Error if file exists already.
+Create parent directories as needed.
+If EXECUTABLE is non-nil, set execute permissions on file.
+Ensure FILEPATH is within `chime-test-base-dir`."
+ (let* ((base (file-name-as-directory chime-test-base-dir))
+ (fullpath (expand-file-name filepath base))
+ (parent-dir (file-name-directory fullpath)))
+ (unless (string-prefix-p base fullpath)
+ (error "File path %s is outside base test directory %s" fullpath base))
+ (when (file-exists-p fullpath)
+ (error "File already exists: %s" fullpath))
+ (unless (file-directory-p parent-dir)
+ (make-directory parent-dir t))
+ (with-temp-buffer
+ (when content
+ (insert content))
+ (write-file fullpath))
+ (when executable
+ (chmod fullpath #o755))
+ fullpath))
+
+(defun chime-create-directory-or-file-ensuring-parents (path &optional content executable)
+ "Create a directory or file specified by PATH relative to `chime-test-base-dir`.
+If PATH ends with a slash, create nested directories.
+Else create a file with optional CONTENT.
+If EXECUTABLE is non-nil and creating a file, set executable permissions.
+Error if the target path already exists.
+Return the full created path."
+ (let ((is-dir (string-suffix-p "/" path)))
+ (if is-dir
+ (chime-create--directory-ensuring-parents path)
+ (chime-create--file-ensuring-parents path content executable))))
+
+
+;; (defun chime-create-file-with-content-ensuring-parents (filepath content &optional executable)
+;; "Create a file at FILEPATH with CONTENT, ensuring parent directories exist.
+;; FILEPATH will be relative to `chime-test-base-dir'.
+;; Signals an error if the file already exists.
+;; If EXECUTABLE is non-nil, set executable permission on the file.
+;; Errors if the resulting path is outside `chime-test-base-dir`."
+;; (let* ((base (file-name-as-directory chime-test-base-dir))
+;; (fullpath (if (file-name-absolute-p filepath)
+;; (expand-file-name filepath)
+;; (expand-file-name filepath base))))
+;; (unless (string-prefix-p base fullpath)
+;; (error "File path %s is outside base test directory %s" fullpath base))
+;; (let ((parent-dir (file-name-directory fullpath)))
+;; (when (file-exists-p fullpath)
+;; (error "File already exists: %s" fullpath))
+;; (unless (file-directory-p parent-dir)
+;; (make-directory parent-dir t))
+;; (with-temp-buffer
+;; (insert content)
+;; (write-file fullpath))
+;; (when executable
+;; (chmod fullpath #o755))
+;; fullpath)))
+
+(defun chime-fix-permissions-recursively (dir)
+ "Recursively set read/write permissions for user under DIR.
+Directories get user read, write, and execute permissions to allow recursive
+operations."
+ (when (file-directory-p dir)
+ (dolist (entry (directory-files-recursively dir ".*" t))
+ (when (file-exists-p entry)
+ (let* ((attrs (file-attributes entry))
+ (is-dir (car attrs))
+ (mode (file-modes entry))
+ (user-r (logand #o400 mode))
+ (user-w (logand #o200 mode))
+ (user-x (logand #o100 mode))
+ new-mode)
+ (setq new-mode mode)
+ (unless user-r
+ (setq new-mode (logior new-mode #o400)))
+ (unless user-w
+ (setq new-mode (logior new-mode #o200)))
+ (when is-dir
+ ;; Ensure user-execute for directories
+ (unless user-x
+ (setq new-mode (logior new-mode #o100))))
+ (unless (= mode new-mode)
+ (set-file-modes entry new-mode)))))))
+
+(defun chime-delete-test-base-dir ()
+ "Recursively delete test base directory `chime-test-base-dir' and contents.
+Ensures all contained files and directories have user read/write permissions
+so deletion is not blocked by permissions.
+After deletion, verifies that the directory no longer exists.
+Signals an error if the directory still exists after deletion attempt."
+ (let ((dir (file-name-as-directory chime-test-base-dir)))
+ (when (file-directory-p dir)
+ (chime-fix-permissions-recursively dir)
+ (delete-directory dir t))
+ (when (file-directory-p dir)
+ (error "Test base directory %s still exists after deletion" dir))))
+
+(defun chime-create-temp-test-file (&optional prefix)
+ "Create a uniquely named temporary file under `chime-test-base-dir'.
+Optional argument PREFIX is a string to prefix the filename, defaults
+to \"tempfile-\". Returns the absolute path to the newly created empty file.
+Errors if base test directory cannot be created or file creation fails."
+ (let ((base (chime-create-test-base-dir))
+ (file nil))
+ (setq file (make-temp-file (expand-file-name (or prefix "tempfile-") base)))
+ (unless (file-exists-p file)
+ (error "Failed to create temporary test file under %s" base))
+ file))
+
+(defun chime-create-test-subdirectory (subdir)
+ "Ensure subdirectory SUBDIR (relative to `chime-test-base-dir') exists.
+Creates parent directories as needed.
+Returns the absolute path to the subdirectory.
+Signals an error if creation fails.
+SUBDIR must be a relative path string."
+ (let* ((base (chime-create-test-base-dir))
+ (fullpath (expand-file-name subdir base)))
+ (unless (file-directory-p fullpath)
+ (make-directory fullpath t))
+ (if (file-directory-p fullpath) fullpath
+ (error "Failed to create test subdirectory %s" subdir))))
+
+(defun chime-create-temp-test-file-with-content (content &optional prefix)
+ "Create uniquely named temp file in =chime-test-base-dir= and write CONTENT to it.
+Optional PREFIX is a filename prefix string, default \"tempfile-\".
+Returns absolute path to the created file."
+ (let ((file (chime-create-temp-test-file prefix)))
+ (with-temp-buffer
+ (insert content)
+ (write-file file))
+ file))
+
+(provide 'testutil-general)
+;;; testutil-general.el ends here.