all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Jostein Kjønigsen" <jostein@secure.kjonigsen.net>
To: Daniele Nicolodi <daniele@grinta.net>, emacs-devel@gnu.org
Subject: Re: Testing fontification, indentation, and buffer manipulation
Date: Mon, 21 Jan 2019 11:45:39 +0100	[thread overview]
Message-ID: <1548067539.3478998.1639830432.03003247@webmail.messagingengine.com> (raw)
In-Reply-To: <2d777e7b-28d9-36a5-073d-b439fca9706a@grinta.net>

[-- Attachment #1: Type: text/plain, Size: 2616 bytes --]

Hey Daniele.

In several of the (third-party) major-modes I author or maintain, I use
the library "assess" available on MELPA for testing fontification. See:
https://melpa.org/#/assess
For testing indentation, I've also created reference-documents and
completely reindented them in a test and then  compared the results.
This provides some basic (but not complete) coverage, because (depending
on the mode) interactive usage may give different results.
An example. Consider the following line of c/java/javascript/php/c#-
code:
    if (someBool)

The correct indentation for the following line could be:

 - the same as the preceeding line if the next line contains an opening
   bracket ({)- nested one level deeper if it contains a direct expression.

So when pressing enter... Should you indent immediately? And should you
then later on correct the indentation if a user creates a block-start
marker { ?
I'm not sure what the right answer is, but it is an example of something
which will differ in a interactive use-case vs reflowing a completed,
existing document.
If your major-mode has cases like this, you will have to write more
elaborate tests to ensure these too are handled correctly.
That said: I'm not sure if this is the recommended or canonical
approach, but combining these techniques has worked for me in my
projects.
--
Regards
Jostein Kjønigsen

jostein@kjonigsen.net 🍵 jostein@gmail.com
https://jostein.kjonigsen.net


On Sat, Jan 19, 2019, at 4:07 PM, Daniele Nicolodi wrote:
> On 15/01/2019 11:45, Yuri Khan wrote:
>> On Tue, Jan 15, 2019 at 10:52 PM Daniele Nicolodi
>> <daniele@grinta.net> wrote:>> 
>>> I am hacking on beancount-mode (a mode to edit Beancount ledger
>>> files)>>> and I would like to write some automated tests to check the
>>> functionality of the minor mode.  I found ERT, but it seems that
>>> it does>>> not offer any facility to easily test fontification, indentation, or>>> buffer manipulation in general.
>>> 
>>> Is there any facility that would help in writing such tests?
>> 
>> You might want to look at ledger-mode tests. Its approach to
>> fontification testing is:
>> 
>> * Create a temporary buffer.
>> * Put test text into it.
>> * Harvest it back with fontification properties into a data
>>   structure.>> * Test that this structure is equal to the golden output.
>> 
>> https://github.com/ledger/ledger-mode/blob/master/test/test-helper.el#L149>> https://github.com/ledger/ledger-mode/blob/master/test/fontify-test.el> 
> Thanks Yuri, this is very helpful.
> 
> Cheers,
> Dan
> 
> 
> 


[-- Attachment #2: Type: text/html, Size: 4290 bytes --]

  reply	other threads:[~2019-01-21 10:45 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-15 15:43 Testing fontification, indentation, and buffer manipulation Daniele Nicolodi
2019-01-15 18:45 ` Yuri Khan
2019-01-19 15:07   ` Daniele Nicolodi
2019-01-21 10:45     ` Jostein Kjønigsen [this message]
2019-01-21 20:57       ` Richard Stallman
2019-01-23 23:22         ` Phillip Lord
2019-01-24  2:09           ` Stefan Monnier
2019-01-24 10:29             ` Phillip Lord
2019-01-24 14:48               ` Ted Zlatanov
2019-01-26  0:46               ` Stefan Monnier
2019-01-26  7:17                 ` Eli Zaretskii
2019-01-26 10:41                 ` Phillip Lord
2019-02-20 19:59                   ` Core ELPA was: " Phillip Lord
2019-02-27 23:05                     ` Stefan Monnier
2019-03-01 15:55                       ` Phillip Lord
2019-03-01 17:25                         ` Stefan Monnier
2019-03-01 21:39                           ` Phillip Lord
2019-03-01 22:07                             ` Stefan Monnier
2019-03-02 11:14                               ` Phillip Lord
2019-03-03  3:23                                 ` Stefan Monnier
2019-03-03 18:06                                   ` Phillip Lord
2019-03-08  2:51                                     ` Stefan Monnier
2019-03-10 11:45                                       ` Phillip Lord
2019-03-10 18:02                                         ` Stefan Monnier
2019-03-11 22:46                                           ` Phillip Lord
2019-03-12  1:11                                             ` Stefan Monnier
2019-03-12 23:02                                               ` Phillip Lord
2019-03-13 19:05                                                 ` Stefan Monnier
2019-03-13 22:41                                                   ` Phillip Lord
2019-03-02  3:36                           ` Richard Stallman
2019-03-02 11:21                             ` Phillip Lord
2019-03-03  3:00                               ` Richard Stallman
2019-03-03 17:52                                 ` Phillip Lord
2019-03-04  3:27                                   ` Richard Stallman
2019-03-10 11:27                                     ` Phillip Lord
2019-03-11  1:23                                       ` Richard Stallman
2019-03-11 22:08                                         ` Phillip Lord
2019-03-12  3:38                                           ` Richard Stallman
2019-03-12 15:42                                             ` Eli Zaretskii
2019-03-12 15:52                                               ` Robert Pluim
2019-03-12 17:25                                                 ` Eli Zaretskii
2019-03-12 22:49                                                   ` Phillip Lord
2019-03-12 22:48                                                 ` Phillip Lord
2019-03-12 18:37                                               ` XEmacs packages (was: Core ELPA was: Testing fontification, indentation, and buffer manipulation) Stefan Monnier
2019-03-13  3:32                                               ` Core ELPA was: Testing fontification, indentation, and buffer manipulation Richard Stallman
2019-01-16  7:58 ` Helmut Eller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1548067539.3478998.1639830432.03003247@webmail.messagingengine.com \
    --to=jostein@secure.kjonigsen.net \
    --cc=daniele@grinta.net \
    --cc=emacs-devel@gnu.org \
    --cc=jostein@kjonigsen.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.