hi my name is eduardox i'm the author of
an mx package called ev and this talk is
about a new feature of ev called test
blocks
let's start by demo
this is a file in lua that defines these
two functions here
and with it if we type f8 several times
here
the f8s create a lower apple here and
then they send these lines to the rebel
where this line here loads this file
into the repo and these other lines here
are tests for these lines
there's a lot of information here so let
me organize them in a more visual way
this is our file in lua
lua sees this thing as a as a multi-line
comment but we are going to see it as a
test block and eev mode is active and so
f8 does the right thing
uh these three lines here set up the
target buffer running a lower apple you
can see the the prompt of the rebel here
and these lines here are sent to the
rebel
and when we type f8 on the line that
starts
with the red star like these lines here
what if it does is that it sends the
rest of the line sorry it
executes the rest of the line as lisp
so it executes the three effects here
executes these lines as lisp and they
set up the target buffer here
and when we type f8 on the line that
does not start with the red star
the f8 sends the line to the target
buffer and moves down
and this line loads this file under
apple and these lines are tests
so we just saw how to use an existing
test block let's now see how to create a
new test block we just have to run this
meta x e insert test block
or meta x euat
and the result depends on the major mode
uh let's see let's understand that that
by looking at the source code
eeit is an alias to this function here
and this function is just five lines of
code plus a dot string
and the dot string explains that if the
major mode is full mode then this
function tries to call
a function called e insert test plot
test full mode if that function exists
and that if that function does not exist
then it yields an error
and here's an example of one such
function that's a function that
inserts a test block in haskell mode
and here we can see two functions like
this one for haskell mode and one for
javascript mode
uh these functions look quite similar
but
their effects look quite different
to make this comparison here i started
by writing
by creating seven files each one in a
different language
and initially each one of these files
only had a comment with the name of the
language so c haskell javascript org
mode etc
and in each one of these files i typed
meta x eeit to insert the test block
so here we can see that these test
blocks are different
for example the syntax for multi-line
comments is different depending on the
language
uh this block here that selects which
rebel to run is also different
this line here that shows how that
tells the repo to
load the current file is also different
depending on the language
in some cases i had to improvise a bit
for example
uh to implement test blocks in shell
mode i had to use this
this with syntax using a rear document
in tcl i also had to improvise a bit and
in some cases i had to improvise a lot
for example in org mode there isn't an
obvious rebel to run and there isn't an
obvious way to load the
the current org file into the repo so
the default action of meta x eeit
in log mode is just to insert this thing
here
that we can use to run a
shell in a rebel
so
these functions are quite similar and in
the beginning i was writing all of them
by hand but then i got bored and i wrote
a function to help you write functions
like that
this function is called
find e-uit-links and it creates a
temporary buffer
and the contents of this temporary
buffer depends on the major mode for
example if the current mode is python
mode then running this function here
creates a temporary buffer that lets me
write the support for
test blocks into python mode or rewrite
the function that supports test blocks
and python mode
so if i'm in python mode and i run this
i get a temporary buffer like this
in which this thing is my template for
the function usually this thing is
totally wrong i have to rewrite to this
string
but the rest is right you can see python
mode here in the name of the function so
we have to edit this and save that to
our home
slash.mx and by the way these things
here hyperlinks to many different things
this elias piper link here
points to the source code to the section
in which
these
functions are defined
so you can see this here the function
that supports c
the function for haskell the function
for javascript etc
and that's it this is a five-minute talk
so i can't say much
if you want more information or if you
want to see real world examples how i
use test blocks etc etc see this page
here and i do not have time to explain
this by the way here
so that's it thanks