Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r70977 - in branches/quickbook-dev/tools/quickbook: src test test/unit
From: dnljms_at_[hidden]
Date: 2011-04-04 18:10:47


Author: danieljames
Date: 2011-04-04 18:10:45 EDT (Mon, 04 Apr 2011)
New Revision: 70977
URL: http://svn.boost.org/trac/boost/changeset/70977

Log:
Quickbook: Overwrite duplicate macros in 1.6
Added:
   branches/quickbook-dev/tools/quickbook/test/macro-1.5.gold
      - copied, changed from r70976, /branches/quickbook-dev/tools/quickbook/test/macro.gold
   branches/quickbook-dev/tools/quickbook/test/macro-1.5.quickbook (contents, props changed)
   branches/quickbook-dev/tools/quickbook/test/macro-1.6.gold (contents, props changed)
      - copied, changed from r70976, /branches/quickbook-dev/tools/quickbook/test/macro.gold
   branches/quickbook-dev/tools/quickbook/test/macro-1.6.quickbook (contents, props changed)
Removed:
   branches/quickbook-dev/tools/quickbook/test/macro.gold
   branches/quickbook-dev/tools/quickbook/test/macro.quickbook
Text files modified:
   branches/quickbook-dev/tools/quickbook/src/actions.cpp | 14 +++++++++
   branches/quickbook-dev/tools/quickbook/src/symbols.hpp | 61 +++++++++++++++++++--------------------
   branches/quickbook-dev/tools/quickbook/test/Jamfile.v2 | 3 +
   branches/quickbook-dev/tools/quickbook/test/macro-1.5.gold | 6 +++
   branches/quickbook-dev/tools/quickbook/test/macro-1.6.gold | 9 +++++
   branches/quickbook-dev/tools/quickbook/test/unit/symbols_tests.cpp | 49 ++++++++++++++++++++++++++++++++
   6 files changed, 109 insertions(+), 33 deletions(-)

Modified: branches/quickbook-dev/tools/quickbook/src/actions.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/actions.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/actions.cpp 2011-04-04 18:10:45 EDT (Mon, 04 Apr 2011)
@@ -899,6 +899,20 @@
         std::string phrase = values.consume().get_boostbook();
         values.finish();
 
+ std::string* existing_macro =
+ boost::spirit::classic::find(actions.macro, macro_id.c_str());
+ quickbook::ignore_variable(&existing_macro);
+
+ if (existing_macro)
+ {
+ if (qbk_version_n < 106) return;
+
+ // Do this if you're using spirit's TST.
+ //
+ // *existing_macro = phrase;
+ // return;
+ }
+
         actions.macro.add(
             macro_id.begin()
           , macro_id.end()

Modified: branches/quickbook-dev/tools/quickbook/src/symbols.hpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/src/symbols.hpp (original)
+++ branches/quickbook-dev/tools/quickbook/src/symbols.hpp 2011-04-04 18:10:45 EDT (Mon, 04 Apr 2011)
@@ -121,7 +121,6 @@
             root.swap(other.root);
         }
 
- // TODO: Make sure you check for readdition.
         template <typename IteratorT>
         T* add(IteratorT first, IteratorT const& last, T const& data)
         {
@@ -134,14 +133,11 @@
             BOOST_SPIRIT_ASSERT((first == last || ch != 0)
                 && "Won't add string containing null character");
 
- for (;;)
+ while(ch != CharT(0))
             {
- if (!*np || ch == 0)
+ if (!*np)
                 {
- node_ptr right = *np;
                     *np = new node_t(ch);
- if (right)
- (*np)->right = right;
                 }
                 else if ((*np)->reference_count > 1)
                 {
@@ -152,37 +148,38 @@
                 {
                     np = &(*np)->left;
                 }
+ else if (ch == (*np)->value)
+ {
+ ++first;
+ ch = (first == last) ? CharT(0) : *first;
+ BOOST_SPIRIT_ASSERT((first == last || ch != 0)
+ && "Won't add string containing null character");
+ np = &(*np)->middle;
+ }
                 else
                 {
- if (ch == (*np)->value)
- {
- if (ch == 0)
- {
- if ((*np)->data == 0)
- {
- (*np)->data = new T(data);
- return (*np)->data;
- }
- else
- {
- // re-addition is disallowed
- return 0;
- }
- }
- ++first;
- ch = (first == last) ? CharT(0) : *first;
- BOOST_SPIRIT_ASSERT((first == last || ch != 0)
- && "Won't add string containing null character");
- np = &(*np)->middle;
- }
- else
- {
- np = &(*np)->right;
- }
+ np = &(*np)->right;
                 }
             }
- }
 
+ if (*np && (*np)->value == CharT(0))
+ {
+ node_ptr new_node = new node_t(ch);
+ new_node->left = (*np)->left;
+ new_node->right = (*np)->right;
+ *np = new_node;
+ }
+ else
+ {
+ node_ptr new_node = new node_t(ch);
+ new_node->right = *np;
+ *np = new_node;
+ }
+
+ (*np)->data = new T(data);
+ return (*np)->data;
+ }
+
         template <typename ScannerT>
         search_info find(ScannerT const& scan) const
         {

Modified: branches/quickbook-dev/tools/quickbook/test/Jamfile.v2
==============================================================================
--- branches/quickbook-dev/tools/quickbook/test/Jamfile.v2 (original)
+++ branches/quickbook-dev/tools/quickbook/test/Jamfile.v2 2011-04-04 18:10:45 EDT (Mon, 04 Apr 2011)
@@ -54,7 +54,8 @@
     [ quickbook-test image_1_5 ]
     [ quickbook-test list_test ]
     [ quickbook-test cond_phrase ]
- [ quickbook-test macro ]
+ [ quickbook-test macro-1.5 ]
+ [ quickbook-test macro-1.6 ]
     [ quickbook-test callouts ]
     [ quickbook-test simple_markup ]
     [ quickbook-test xml-escape_1_2 ]

Copied: branches/quickbook-dev/tools/quickbook/test/macro-1.5.gold (from r70976, /branches/quickbook-dev/tools/quickbook/test/macro.gold)
==============================================================================
--- /branches/quickbook-dev/tools/quickbook/test/macro.gold (original)
+++ branches/quickbook-dev/tools/quickbook/test/macro-1.5.gold 2011-04-04 18:10:45 EDT (Mon, 04 Apr 2011)
@@ -11,4 +11,10 @@
   <para>
     two
   </para>
+ <para>
+ 1
+ </para>
+ <para>
+ 1
+ </para>
 </article>

Added: branches/quickbook-dev/tools/quickbook/test/macro-1.5.quickbook
==============================================================================
--- (empty file)
+++ branches/quickbook-dev/tools/quickbook/test/macro-1.5.quickbook 2011-04-04 18:10:45 EDT (Mon, 04 Apr 2011)
@@ -0,0 +1,28 @@
+[article Macro Test
+[quickbook 1.5]
+]
+
+[def one 1]
+
+one
+
+[template foo[]
+
+[def two 2]
+two
+]
+
+[foo]
+two [/This shouldn't expand]
+
+
+[def __foo__ 1]
+[def __foo__ 2]
+__foo__
+
+[template foo2[]
+[def __foo__ 2]
+__foo__
+]
+
+[foo2]

Copied: branches/quickbook-dev/tools/quickbook/test/macro-1.6.gold (from r70976, /branches/quickbook-dev/tools/quickbook/test/macro.gold)
==============================================================================
--- /branches/quickbook-dev/tools/quickbook/test/macro.gold (original)
+++ branches/quickbook-dev/tools/quickbook/test/macro-1.6.gold 2011-04-04 18:10:45 EDT (Mon, 04 Apr 2011)
@@ -11,4 +11,13 @@
   <para>
     two
   </para>
+ <para>
+ 2
+ </para>
+ <para>
+ 3
+ </para>
+ <para>
+ 2
+ </para>
 </article>

Added: branches/quickbook-dev/tools/quickbook/test/macro-1.6.quickbook
==============================================================================
--- (empty file)
+++ branches/quickbook-dev/tools/quickbook/test/macro-1.6.quickbook 2011-04-04 18:10:45 EDT (Mon, 04 Apr 2011)
@@ -0,0 +1,29 @@
+[article Macro Test
+[quickbook 1.6]
+]
+
+[def one 1]
+
+one
+
+[template foo[]
+
+[def two 2]
+two
+]
+
+[foo]
+two [/This shouldn't expand]
+
+
+[def __foo__ 1]
+[def __foo__ 2]
+__foo__
+
+[template foo2[]
+[def __foo__ 3]
+__foo__
+]
+
+[foo2]
+__foo__

Deleted: branches/quickbook-dev/tools/quickbook/test/macro.gold
==============================================================================
--- branches/quickbook-dev/tools/quickbook/test/macro.gold 2011-04-04 18:10:45 EDT (Mon, 04 Apr 2011)
+++ (empty file)
@@ -1,14 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE article PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN" "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
-<article id="macro_test" last-revision="DEBUG MODE Date: 2000/12/20 12:00:00 $" xmlns:xi="http://www.w3.org/2001/XInclude">
- <title>Macro Test</title>
- <para>
- 1
- </para>
- <para>
- 2
- </para>
- <para>
- two
- </para>
-</article>

Deleted: branches/quickbook-dev/tools/quickbook/test/macro.quickbook
==============================================================================
--- branches/quickbook-dev/tools/quickbook/test/macro.quickbook 2011-04-04 18:10:45 EDT (Mon, 04 Apr 2011)
+++ (empty file)
@@ -1,16 +0,0 @@
-[article Macro Test
-[quickbook 1.5]
-]
-
-[def one 1]
-
-one
-
-[template foo[]
-
-[def two 2]
-two
-]
-
-[foo]
-two [/This shouldn't expand]
\ No newline at end of file

Modified: branches/quickbook-dev/tools/quickbook/test/unit/symbols_tests.cpp
==============================================================================
--- branches/quickbook-dev/tools/quickbook/test/unit/symbols_tests.cpp (original)
+++ branches/quickbook-dev/tools/quickbook/test/unit/symbols_tests.cpp 2011-04-04 18:10:45 EDT (Mon, 04 Apr 2011)
@@ -331,10 +331,58 @@
     nsymbols sym;
     BOOST_TEST(*add(sym, "a", 0) == 0);
     BOOST_TEST(*add(sym, "a2", 1) == 1);
+ BOOST_TEST(add(sym, "a2", 2) == 0);
     BOOST_TEST(find(sym, "a2"));
     BOOST_TEST(find(sym, "a"));
 }
 
+// The original teneray search tree implementation contained a bug when
+// inserting duplicate values. I want this implementation to be as
+// close as possible to the original (so they can be easily switched)
+// so check that the bug remains the same.
+
+struct check_parse_value
+{
+ explicit check_parse_value(int value) : value_(value){}
+
+ void operator()(int value) const { BOOST_TEST(value == value_); }
+
+ int value_;
+};
+
+// My version is different to the original, if there's an existing value
+// it replaces it with the new one.
+
+static
+void duplicate_add_tests()
+{
+ char const* foo1 = "foo";
+ char const* foo2 = foo1 + 3;
+
+ nsymbols sym;
+ sym.add(foo1, foo2, 1);
+ nsymbols sym2 = sym;
+ sym.add(foo1, foo2, 2);
+ sym2.add(foo1, foo2, 3);
+
+ BOOST_TEST(find(sym, "foo") && *find(sym, "foo") == 2);
+ BOOST_TEST(find(sym2, "foo") && *find(sym2, "foo") == 3);
+
+ parse_info<char const*> info;
+
+ info = parse("foo ", sym[check_parse_value(2)]);
+ BOOST_TEST(info.hit && info.length == 3);
+
+ info = parse("foo", sym[check_parse_value(2)]);
+ BOOST_TEST(info.hit && info.length == 3);
+
+ info = parse("foo ", sym2[check_parse_value(3)]);
+ BOOST_TEST(info.hit && info.length == 3);
+
+ info = parse("foo", sym2[check_parse_value(3)]);
+ BOOST_TEST(info.hit && info.length == 3);
+}
+
 int
 main()
 {
@@ -352,5 +400,6 @@
     wide_value_tests();
     wide_free_functions_tests();
     free_add_find_functions_tests();
+ duplicate_add_tests();
     return boost::report_errors();
 }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk