From 450bd01ed7355f7420cf436d60620f4078661eff Mon Sep 17 00:00:00 2001
From: John Darrington <john@darrington.wattle.id.au>
Date: Wed, 7 Oct 2015 11:28:35 +0200
Subject: [PATCH] Fix the INCLUDE /ENCODING subcommand and add a test for it.

It seems that INCLUDE /ENCODING had never worked nor had been
tested.
---
 src/language/utilities/include.c   |  1 +
 tests/language/utilities/insert.at | 23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/src/language/utilities/include.c b/src/language/utilities/include.c
index a05456e2a2..b0823eafcb 100644
--- a/src/language/utilities/include.c
+++ b/src/language/utilities/include.c
@@ -90,6 +90,7 @@ do_insert (struct lexer *lexer, struct dataset *ds, enum variant variant)
 
           free (encoding);
           encoding = xstrdup (lex_tokcstr (lexer));
+	  lex_get (lexer);
         }
       else if (variant == INSERT && lex_match_id (lexer, "SYNTAX"))
 	{
diff --git a/tests/language/utilities/insert.at b/tests/language/utilities/insert.at
index 8eaa72f726..e8e76502da 100644
--- a/tests/language/utilities/insert.at
+++ b/tests/language/utilities/insert.at
@@ -158,3 +158,26 @@ insert.sps:2: error: INSERT: Can't find `nonexistent' in include file search pat
 insert.sps:6: error: LIST: LIST is allowed only after the active dataset has been defined.
 ])
 AT_CLEANUP
+
+
+dnl A test to check the INCLUDE command complete with the 
+dnl syntax and function of the ENCODING subcommand.
+AT_SETUP([INCLUDE full check])
+AT_DATA([two-utf8.sps], [dnl
+echo 'Äpfelfölfaß'.
+])
+
+AT_DATA([include.sps], [dnl
+echo 'ONE'.
+
+include FILE='two-latin1.sps' ENCODING='ISO_8859-1'.
+])
+
+AT_CHECK([iconv -f UTF-8 -t iso-8859-1 two-utf8.sps > two-latin1.sps], [0], [])
+
+AT_CHECK([pspp -O format=csv include.sps], [0], [dnl
+ONE
+
+Äpfelfölfaß
+])
+AT_CLEANUP
-- 
2.30.2