aboutsummaryrefslogtreecommitdiff
path: root/tests/web/xhtml/driver.cxx
blob: 7d9a536bc38700937dd2a25bd54e4f413b3ef424 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// file      : tests/web/xhtml/driver.cxx -*- C++ -*-
// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
// license   : MIT; see accompanying LICENSE file

#include <iostream>
#include <functional>

#include <xml/serializer>

#include <web/xhtml.hxx>

using namespace std;
using namespace xml;

static bool
bad_sequence (const function<void(serializer& s)>& f)
{
  ostringstream o;
  serializer s (o, "osstream");

  try
  {
    f (s);
    return false;
  }
  catch (const serialization&)
  {
    return true;
  }
}

int
main ()
{
  using namespace web::xhtml;

  assert (bad_sequence ([](serializer& s) {s << HTML << ~HEAD;}));
  assert (bad_sequence ([](serializer& s) {s << HTML << DIV << ~P << ~HTML;}));
  assert (bad_sequence ([](serializer& s) {s << HTML << DIV << ~A << ~HTML;}));
  assert (bad_sequence ([](serializer& s) {s << P << A << "a" << ~P << ~P;}));
  assert (bad_sequence ([](serializer& s) {s << P << A << "a" << ~I << ~P;}));

  assert (
    bad_sequence (
      [](serializer& s) {s << P << A << ID << "A" << ~HREF << ~A << ~P;}));

  serializer s (cout, "output");

  s << HTML
    <<   HEAD
    <<     TITLE << "Example XHTML5 document" << ~TITLE
    <<   ~HEAD
    <<   BODY
    //
    // Inline elements (no indentation).
    //
    <<     P << "Here be " << B << "Dragons!" << ~B << *BR
    <<       "and a newline" << ~P
    //
    // Various ways to specify attributes.
    //
    <<     P(ID=123, CLASS="cool") << "Text" << ~P
    <<     P << (ID=123) << (CLASS="cool") << "Text" << ~P
    <<     P << ID(123) << CLASS("cool") << "Text" << ~P
    <<     P << ID << 123 << ~ID << CLASS << "cool" << ~CLASS << "Text" << ~P
    //
    // Empty element with attributes.
    //
    <<     P << "Text" << *BR(CLASS="double") << ~P
    <<   ~BODY
    << ~HTML;
}