text: // Warning! This file is autogenerated.
  #include <boost/text/bidirectional.hpp>
  
  #include "bidi_tests.hpp"
  
  #include <gtest/gtest.h>
  
  #include <algorithm>
  
  
  std::vector<int> expected_levels;
  std::vector<int> expected_reordered_indices;
  
  TEST(bidi, bidi_927_000)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // FSI ET S RLI; 4 ('RTL') (line 463501)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x0009, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET S FSI; 4 ('RTL') (line 463502)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x0009, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET S PDI; 4 ('RTL') (line 463503)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x0009, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET WS B; 4 ('RTL') (line 463504)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x0020, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET WS S; 4 ('RTL') (line 463505)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x0020, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET WS WS; 4 ('RTL') (line 463506)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x0020, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET WS LRI; 4 ('RTL') (line 463507)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x0020, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET WS RLI; 4 ('RTL') (line 463508)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x0020, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET WS FSI; 4 ('RTL') (line 463509)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x0020, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET WS PDI; 4 ('RTL') (line 463510)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x0020, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_001)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // FSI ET LRI B; 4 ('RTL') (line 463511)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2066, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET LRI S; 4 ('RTL') (line 463512)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2066, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET LRI WS; 4 ('RTL') (line 463513)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2066, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET LRI LRI; 4 ('RTL') (line 463514)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2066, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET LRI RLI; 4 ('RTL') (line 463515)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2066, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET LRI FSI; 4 ('RTL') (line 463516)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2066, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET LRI PDI; 4 ('RTL') (line 463517)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2066, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET RLI B; 4 ('RTL') (line 463518)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2067, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET RLI S; 4 ('RTL') (line 463519)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2067, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET RLI WS; 4 ('RTL') (line 463520)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2067, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_002)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // FSI ET RLI LRI; 4 ('RTL') (line 463521)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2067, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET RLI RLI; 4 ('RTL') (line 463522)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2067, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET RLI FSI; 4 ('RTL') (line 463523)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2067, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET RLI PDI; 4 ('RTL') (line 463524)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2067, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET FSI B; 4 ('RTL') (line 463525)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2068, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET FSI S; 4 ('RTL') (line 463526)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2068, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET FSI WS; 4 ('RTL') (line 463527)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2068, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET FSI LRI; 4 ('RTL') (line 463528)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2068, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET FSI RLI; 4 ('RTL') (line 463529)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2068, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET FSI FSI; 4 ('RTL') (line 463530)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2068, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_003)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // FSI ET FSI PDI; 4 ('RTL') (line 463531)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2068, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET PDI R; 5 ('auto') (line 463532)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2069, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET PDI R; 5 ('RTL') (line 463532)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2069, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET PDI AL; 5 ('auto') (line 463533)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2069, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET PDI AL; 5 ('RTL') (line 463533)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2069, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET PDI ES; 4 ('RTL') (line 463534)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2069, 0x002B };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET PDI ET; 4 ('RTL') (line 463535)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2069, 0x0023 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET PDI CS; 4 ('RTL') (line 463536)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2069, 0x002C };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET PDI NSM; 4 ('RTL') (line 463537)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2069, 0x0300 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET PDI B; 4 ('RTL') (line 463538)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2069, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET PDI S; 4 ('RTL') (line 463539)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2069, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET PDI WS; 4 ('RTL') (line 463540)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2069, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_004)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // FSI ET PDI ON; 4 ('RTL') (line 463541)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2069, 0x0021 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET PDI LRI; 4 ('RTL') (line 463542)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2069, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET PDI RLI; 4 ('RTL') (line 463543)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2069, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET PDI FSI; 4 ('RTL') (line 463544)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2069, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ET PDI PDI; 4 ('RTL') (line 463545)
          std::vector<uint32_t> const cps = { 0x2068, 0x0023, 0x2069, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS S B; 4 ('RTL') (line 463546)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x0009, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS S S; 4 ('RTL') (line 463547)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x0009, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS S WS; 4 ('RTL') (line 463548)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x0009, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS S LRI; 4 ('RTL') (line 463549)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x0009, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS S RLI; 4 ('RTL') (line 463550)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x0009, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_005)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // FSI CS S FSI; 4 ('RTL') (line 463551)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x0009, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS S PDI; 4 ('RTL') (line 463552)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x0009, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS WS B; 4 ('RTL') (line 463553)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x0020, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS WS S; 4 ('RTL') (line 463554)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x0020, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS WS WS; 4 ('RTL') (line 463555)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x0020, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS WS LRI; 4 ('RTL') (line 463556)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x0020, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS WS RLI; 4 ('RTL') (line 463557)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x0020, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS WS FSI; 4 ('RTL') (line 463558)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x0020, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS WS PDI; 4 ('RTL') (line 463559)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x0020, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS LRI B; 4 ('RTL') (line 463560)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2066, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_006)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // FSI CS LRI S; 4 ('RTL') (line 463561)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2066, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS LRI WS; 4 ('RTL') (line 463562)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2066, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS LRI LRI; 4 ('RTL') (line 463563)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2066, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS LRI RLI; 4 ('RTL') (line 463564)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2066, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS LRI FSI; 4 ('RTL') (line 463565)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2066, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS LRI PDI; 4 ('RTL') (line 463566)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2066, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS RLI B; 4 ('RTL') (line 463567)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2067, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS RLI S; 4 ('RTL') (line 463568)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2067, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS RLI WS; 4 ('RTL') (line 463569)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2067, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS RLI LRI; 4 ('RTL') (line 463570)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2067, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_007)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // FSI CS RLI RLI; 4 ('RTL') (line 463571)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2067, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS RLI FSI; 4 ('RTL') (line 463572)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2067, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS RLI PDI; 4 ('RTL') (line 463573)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2067, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS FSI B; 4 ('RTL') (line 463574)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2068, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS FSI S; 4 ('RTL') (line 463575)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2068, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS FSI WS; 4 ('RTL') (line 463576)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2068, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS FSI LRI; 4 ('RTL') (line 463577)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2068, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS FSI RLI; 4 ('RTL') (line 463578)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2068, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS FSI FSI; 4 ('RTL') (line 463579)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2068, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS FSI PDI; 4 ('RTL') (line 463580)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2068, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_008)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // FSI CS PDI R; 5 ('auto') (line 463581)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2069, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS PDI R; 5 ('RTL') (line 463581)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2069, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS PDI AL; 5 ('auto') (line 463582)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2069, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS PDI AL; 5 ('RTL') (line 463582)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2069, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS PDI ES; 4 ('RTL') (line 463583)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2069, 0x002B };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS PDI ET; 4 ('RTL') (line 463584)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2069, 0x0023 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS PDI CS; 4 ('RTL') (line 463585)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2069, 0x002C };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS PDI NSM; 4 ('RTL') (line 463586)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2069, 0x0300 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS PDI B; 4 ('RTL') (line 463587)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2069, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS PDI S; 4 ('RTL') (line 463588)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2069, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS PDI WS; 4 ('RTL') (line 463589)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2069, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS PDI ON; 4 ('RTL') (line 463590)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2069, 0x0021 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_009)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // FSI CS PDI LRI; 4 ('RTL') (line 463591)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2069, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS PDI RLI; 4 ('RTL') (line 463592)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2069, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS PDI FSI; 4 ('RTL') (line 463593)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2069, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI CS PDI PDI; 4 ('RTL') (line 463594)
          std::vector<uint32_t> const cps = { 0x2068, 0x002C, 0x2069, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM S B; 4 ('RTL') (line 463595)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x0009, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM S S; 4 ('RTL') (line 463596)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x0009, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM S WS; 4 ('RTL') (line 463597)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x0009, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM S LRI; 4 ('RTL') (line 463598)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x0009, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM S RLI; 4 ('RTL') (line 463599)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x0009, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM S FSI; 4 ('RTL') (line 463600)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x0009, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_010)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // FSI NSM S PDI; 4 ('RTL') (line 463601)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x0009, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM WS B; 4 ('RTL') (line 463602)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x0020, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM WS S; 4 ('RTL') (line 463603)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x0020, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM WS WS; 4 ('RTL') (line 463604)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x0020, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM WS LRI; 4 ('RTL') (line 463605)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x0020, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM WS RLI; 4 ('RTL') (line 463606)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x0020, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM WS FSI; 4 ('RTL') (line 463607)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x0020, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM WS PDI; 4 ('RTL') (line 463608)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x0020, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM LRI B; 4 ('RTL') (line 463609)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2066, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM LRI S; 4 ('RTL') (line 463610)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2066, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_011)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // FSI NSM LRI WS; 4 ('RTL') (line 463611)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2066, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM LRI LRI; 4 ('RTL') (line 463612)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2066, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM LRI RLI; 4 ('RTL') (line 463613)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2066, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM LRI FSI; 4 ('RTL') (line 463614)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2066, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM LRI PDI; 4 ('RTL') (line 463615)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2066, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM RLI B; 4 ('RTL') (line 463616)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2067, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM RLI S; 4 ('RTL') (line 463617)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2067, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM RLI WS; 4 ('RTL') (line 463618)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2067, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM RLI LRI; 4 ('RTL') (line 463619)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2067, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM RLI RLI; 4 ('RTL') (line 463620)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2067, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_012)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // FSI NSM RLI FSI; 4 ('RTL') (line 463621)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2067, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM RLI PDI; 4 ('RTL') (line 463622)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2067, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM FSI B; 4 ('RTL') (line 463623)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2068, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM FSI S; 4 ('RTL') (line 463624)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2068, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM FSI WS; 4 ('RTL') (line 463625)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2068, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM FSI LRI; 4 ('RTL') (line 463626)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2068, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM FSI RLI; 4 ('RTL') (line 463627)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2068, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM FSI FSI; 4 ('RTL') (line 463628)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2068, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM FSI PDI; 4 ('RTL') (line 463629)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2068, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM PDI R; 5 ('auto') (line 463630)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2069, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM PDI R; 5 ('RTL') (line 463630)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2069, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_013)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // FSI NSM PDI AL; 5 ('auto') (line 463631)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2069, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM PDI AL; 5 ('RTL') (line 463631)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2069, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM PDI ES; 4 ('RTL') (line 463632)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2069, 0x002B };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM PDI ET; 4 ('RTL') (line 463633)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2069, 0x0023 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM PDI CS; 4 ('RTL') (line 463634)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2069, 0x002C };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM PDI NSM; 4 ('RTL') (line 463635)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2069, 0x0300 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM PDI B; 4 ('RTL') (line 463636)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2069, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM PDI S; 4 ('RTL') (line 463637)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2069, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM PDI WS; 4 ('RTL') (line 463638)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2069, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM PDI ON; 4 ('RTL') (line 463639)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2069, 0x0021 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM PDI LRI; 4 ('RTL') (line 463640)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2069, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_014)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // FSI NSM PDI RLI; 4 ('RTL') (line 463641)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2069, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM PDI FSI; 4 ('RTL') (line 463642)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2069, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI NSM PDI PDI; 4 ('RTL') (line 463643)
          std::vector<uint32_t> const cps = { 0x2068, 0x0300, 0x2069, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI WS PDI R; 5 ('auto') (line 463644)
          std::vector<uint32_t> const cps = { 0x2068, 0x0020, 0x2069, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI WS PDI R; 5 ('RTL') (line 463644)
          std::vector<uint32_t> const cps = { 0x2068, 0x0020, 0x2069, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI WS PDI AL; 5 ('auto') (line 463645)
          std::vector<uint32_t> const cps = { 0x2068, 0x0020, 0x2069, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI WS PDI AL; 5 ('RTL') (line 463645)
          std::vector<uint32_t> const cps = { 0x2068, 0x0020, 0x2069, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI WS PDI ES; 4 ('RTL') (line 463646)
          std::vector<uint32_t> const cps = { 0x2068, 0x0020, 0x2069, 0x002B };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI WS PDI ET; 4 ('RTL') (line 463647)
          std::vector<uint32_t> const cps = { 0x2068, 0x0020, 0x2069, 0x0023 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI WS PDI CS; 4 ('RTL') (line 463648)
          std::vector<uint32_t> const cps = { 0x2068, 0x0020, 0x2069, 0x002C };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI WS PDI NSM; 4 ('RTL') (line 463649)
          std::vector<uint32_t> const cps = { 0x2068, 0x0020, 0x2069, 0x0300 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI WS PDI ON; 4 ('RTL') (line 463650)
          std::vector<uint32_t> const cps = { 0x2068, 0x0020, 0x2069, 0x0021 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_015)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // FSI ON S B; 4 ('RTL') (line 463651)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x0009, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON S S; 4 ('RTL') (line 463652)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x0009, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON S WS; 4 ('RTL') (line 463653)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x0009, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON S LRI; 4 ('RTL') (line 463654)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x0009, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON S RLI; 4 ('RTL') (line 463655)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x0009, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON S FSI; 4 ('RTL') (line 463656)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x0009, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON S PDI; 4 ('RTL') (line 463657)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x0009, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON WS B; 4 ('RTL') (line 463658)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x0020, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON WS S; 4 ('RTL') (line 463659)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x0020, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON WS WS; 4 ('RTL') (line 463660)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x0020, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_016)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // FSI ON WS LRI; 4 ('RTL') (line 463661)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x0020, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON WS RLI; 4 ('RTL') (line 463662)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x0020, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON WS FSI; 4 ('RTL') (line 463663)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x0020, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON WS PDI; 4 ('RTL') (line 463664)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x0020, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON LRI B; 4 ('RTL') (line 463665)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2066, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON LRI S; 4 ('RTL') (line 463666)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2066, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON LRI WS; 4 ('RTL') (line 463667)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2066, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON LRI LRI; 4 ('RTL') (line 463668)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2066, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON LRI RLI; 4 ('RTL') (line 463669)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2066, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON LRI FSI; 4 ('RTL') (line 463670)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2066, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_017)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // FSI ON LRI PDI; 4 ('RTL') (line 463671)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2066, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON RLI B; 4 ('RTL') (line 463672)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2067, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON RLI S; 4 ('RTL') (line 463673)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2067, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON RLI WS; 4 ('RTL') (line 463674)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2067, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON RLI LRI; 4 ('RTL') (line 463675)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2067, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON RLI RLI; 4 ('RTL') (line 463676)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2067, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON RLI FSI; 4 ('RTL') (line 463677)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2067, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON RLI PDI; 4 ('RTL') (line 463678)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2067, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON FSI B; 4 ('RTL') (line 463679)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2068, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON FSI S; 4 ('RTL') (line 463680)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2068, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_018)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // FSI ON FSI WS; 4 ('RTL') (line 463681)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2068, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON FSI LRI; 4 ('RTL') (line 463682)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2068, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON FSI RLI; 4 ('RTL') (line 463683)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2068, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON FSI FSI; 4 ('RTL') (line 463684)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2068, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON FSI PDI; 4 ('RTL') (line 463685)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2068, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON PDI R; 5 ('auto') (line 463686)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2069, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON PDI R; 5 ('RTL') (line 463686)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2069, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON PDI AL; 5 ('auto') (line 463687)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2069, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON PDI AL; 5 ('RTL') (line 463687)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2069, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON PDI ES; 4 ('RTL') (line 463688)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2069, 0x002B };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON PDI ET; 4 ('RTL') (line 463689)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2069, 0x0023 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON PDI CS; 4 ('RTL') (line 463690)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2069, 0x002C };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_019)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // FSI ON PDI NSM; 4 ('RTL') (line 463691)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2069, 0x0300 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON PDI B; 4 ('RTL') (line 463692)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2069, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON PDI S; 4 ('RTL') (line 463693)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2069, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON PDI WS; 4 ('RTL') (line 463694)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2069, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON PDI ON; 4 ('RTL') (line 463695)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2069, 0x0021 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON PDI LRI; 4 ('RTL') (line 463696)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2069, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON PDI RLI; 4 ('RTL') (line 463697)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2069, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON PDI FSI; 4 ('RTL') (line 463698)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2069, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // FSI ON PDI PDI; 4 ('RTL') (line 463699)
          std::vector<uint32_t> const cps = { 0x2068, 0x0021, 0x2069, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L R R; 4 ('RTL') (line 463700)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x05BE, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_020)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // PDI L R AL; 4 ('RTL') (line 463701)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x05BE, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L R ES; 4 ('RTL') (line 463702)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x05BE, 0x002B };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L R ET; 4 ('RTL') (line 463703)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x05BE, 0x0023 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L R CS; 4 ('RTL') (line 463704)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x05BE, 0x002C };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L R NSM; 4 ('RTL') (line 463705)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x05BE, 0x0300 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L R B; 4 ('RTL') (line 463706)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x05BE, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L R S; 4 ('RTL') (line 463707)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x05BE, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L R WS; 4 ('RTL') (line 463708)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x05BE, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L R ON; 4 ('RTL') (line 463709)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x05BE, 0x0021 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L R LRI; 4 ('RTL') (line 463710)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x05BE, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_021)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // PDI L R RLI; 4 ('RTL') (line 463711)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x05BE, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L R FSI; 4 ('RTL') (line 463712)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x05BE, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L R PDI; 4 ('RTL') (line 463713)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x05BE, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L AL R; 4 ('RTL') (line 463714)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0608, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L AL AL; 4 ('RTL') (line 463715)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0608, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L AL ES; 4 ('RTL') (line 463716)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0608, 0x002B };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L AL ET; 4 ('RTL') (line 463717)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0608, 0x0023 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L AL CS; 4 ('RTL') (line 463718)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0608, 0x002C };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L AL NSM; 4 ('RTL') (line 463719)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0608, 0x0300 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L AL B; 4 ('RTL') (line 463720)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0608, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_022)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // PDI L AL S; 4 ('RTL') (line 463721)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0608, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L AL WS; 4 ('RTL') (line 463722)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0608, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L AL ON; 4 ('RTL') (line 463723)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0608, 0x0021 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L AL LRI; 4 ('RTL') (line 463724)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0608, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L AL RLI; 4 ('RTL') (line 463725)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0608, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L AL FSI; 4 ('RTL') (line 463726)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0608, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L AL PDI; 4 ('RTL') (line 463727)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0608, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ES R; 4 ('RTL') (line 463728)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x002B, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ES AL; 4 ('RTL') (line 463729)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x002B, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ES ES; 4 ('RTL') (line 463730)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x002B, 0x002B };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_023)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // PDI L ES ET; 4 ('RTL') (line 463731)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x002B, 0x0023 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ES CS; 4 ('RTL') (line 463732)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x002B, 0x002C };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ES NSM; 4 ('RTL') (line 463733)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x002B, 0x0300 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ES B; 4 ('RTL') (line 463734)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x002B, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ES S; 4 ('RTL') (line 463735)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x002B, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ES WS; 4 ('RTL') (line 463736)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x002B, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ES ON; 4 ('RTL') (line 463737)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x002B, 0x0021 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ES LRI; 4 ('RTL') (line 463738)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x002B, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ES RLI; 4 ('RTL') (line 463739)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x002B, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ES FSI; 4 ('RTL') (line 463740)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x002B, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_024)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // PDI L ES PDI; 4 ('RTL') (line 463741)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x002B, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ET R; 4 ('RTL') (line 463742)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0023, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ET AL; 4 ('RTL') (line 463743)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0023, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ET ES; 4 ('RTL') (line 463744)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0023, 0x002B };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ET ET; 4 ('RTL') (line 463745)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0023, 0x0023 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ET CS; 4 ('RTL') (line 463746)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0023, 0x002C };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ET NSM; 4 ('RTL') (line 463747)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0023, 0x0300 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ET B; 4 ('RTL') (line 463748)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0023, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ET S; 4 ('RTL') (line 463749)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0023, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ET WS; 4 ('RTL') (line 463750)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0023, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_025)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // PDI L ET ON; 4 ('RTL') (line 463751)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0023, 0x0021 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ET LRI; 4 ('RTL') (line 463752)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0023, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ET RLI; 4 ('RTL') (line 463753)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0023, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ET FSI; 4 ('RTL') (line 463754)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0023, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ET PDI; 4 ('RTL') (line 463755)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0023, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L CS R; 4 ('RTL') (line 463756)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x002C, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L CS AL; 4 ('RTL') (line 463757)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x002C, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L CS ES; 4 ('RTL') (line 463758)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x002C, 0x002B };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L CS ET; 4 ('RTL') (line 463759)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x002C, 0x0023 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L CS CS; 4 ('RTL') (line 463760)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x002C, 0x002C };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_026)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // PDI L CS NSM; 4 ('RTL') (line 463761)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x002C, 0x0300 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L CS B; 4 ('RTL') (line 463762)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x002C, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L CS S; 4 ('RTL') (line 463763)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x002C, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L CS WS; 4 ('RTL') (line 463764)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x002C, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L CS ON; 4 ('RTL') (line 463765)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x002C, 0x0021 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L CS LRI; 4 ('RTL') (line 463766)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x002C, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L CS RLI; 4 ('RTL') (line 463767)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x002C, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L CS FSI; 4 ('RTL') (line 463768)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x002C, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L CS PDI; 4 ('RTL') (line 463769)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x002C, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L S R; 4 ('RTL') (line 463770)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0009, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_027)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // PDI L S AL; 4 ('RTL') (line 463771)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0009, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L S ES; 4 ('RTL') (line 463772)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0009, 0x002B };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L S ET; 4 ('RTL') (line 463773)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0009, 0x0023 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L S CS; 4 ('RTL') (line 463774)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0009, 0x002C };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L S NSM; 4 ('RTL') (line 463775)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0009, 0x0300 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L S B; 4 ('RTL') (line 463776)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0009, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L S S; 4 ('RTL') (line 463777)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0009, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L S WS; 4 ('RTL') (line 463778)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0009, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L S ON; 4 ('RTL') (line 463779)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0009, 0x0021 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L S LRI; 4 ('RTL') (line 463780)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0009, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_028)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // PDI L S RLI; 4 ('RTL') (line 463781)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0009, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L S FSI; 4 ('RTL') (line 463782)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0009, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L S PDI; 4 ('RTL') (line 463783)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0009, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L WS R; 4 ('RTL') (line 463784)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0020, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L WS AL; 4 ('RTL') (line 463785)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0020, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L WS ES; 4 ('RTL') (line 463786)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0020, 0x002B };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L WS ET; 4 ('RTL') (line 463787)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0020, 0x0023 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L WS CS; 4 ('RTL') (line 463788)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0020, 0x002C };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L WS NSM; 4 ('RTL') (line 463789)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0020, 0x0300 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L WS B; 4 ('RTL') (line 463790)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0020, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_029)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // PDI L WS S; 4 ('RTL') (line 463791)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0020, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L WS WS; 4 ('RTL') (line 463792)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0020, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L WS ON; 4 ('RTL') (line 463793)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0020, 0x0021 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L WS LRI; 4 ('RTL') (line 463794)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0020, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L WS RLI; 4 ('RTL') (line 463795)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0020, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L WS FSI; 4 ('RTL') (line 463796)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0020, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L WS PDI; 4 ('RTL') (line 463797)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0020, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ON R; 4 ('RTL') (line 463798)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0021, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ON AL; 4 ('RTL') (line 463799)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0021, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ON ES; 4 ('RTL') (line 463800)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0021, 0x002B };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_030)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // PDI L ON ET; 4 ('RTL') (line 463801)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0021, 0x0023 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ON CS; 4 ('RTL') (line 463802)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0021, 0x002C };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ON NSM; 4 ('RTL') (line 463803)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0021, 0x0300 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ON B; 4 ('RTL') (line 463804)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0021, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ON S; 4 ('RTL') (line 463805)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0021, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ON WS; 4 ('RTL') (line 463806)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0021, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ON ON; 4 ('RTL') (line 463807)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0021, 0x0021 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ON LRI; 4 ('RTL') (line 463808)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0021, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ON RLI; 4 ('RTL') (line 463809)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0021, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L ON FSI; 4 ('RTL') (line 463810)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0021, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_031)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // PDI L ON PDI; 4 ('RTL') (line 463811)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x0021, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L LRI B; 4 ('RTL') (line 463812)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2066, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L LRI S; 4 ('RTL') (line 463813)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2066, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L LRI WS; 4 ('RTL') (line 463814)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2066, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L LRI LRI; 4 ('RTL') (line 463815)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2066, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L LRI RLI; 4 ('RTL') (line 463816)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2066, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L LRI FSI; 4 ('RTL') (line 463817)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2066, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L LRI PDI; 4 ('RTL') (line 463818)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2066, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L RLI B; 4 ('RTL') (line 463819)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2067, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L RLI S; 4 ('RTL') (line 463820)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2067, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_032)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // PDI L RLI WS; 4 ('RTL') (line 463821)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2067, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L RLI LRI; 4 ('RTL') (line 463822)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2067, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L RLI RLI; 4 ('RTL') (line 463823)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2067, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L RLI FSI; 4 ('RTL') (line 463824)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2067, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L RLI PDI; 4 ('RTL') (line 463825)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2067, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L FSI B; 4 ('RTL') (line 463826)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2068, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L FSI S; 4 ('RTL') (line 463827)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2068, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L FSI WS; 4 ('RTL') (line 463828)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2068, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L FSI LRI; 4 ('RTL') (line 463829)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2068, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L FSI RLI; 4 ('RTL') (line 463830)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2068, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_033)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // PDI L FSI FSI; 4 ('RTL') (line 463831)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2068, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L FSI PDI; 4 ('RTL') (line 463832)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2068, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L PDI R; 4 ('RTL') (line 463833)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2069, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L PDI AL; 4 ('RTL') (line 463834)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2069, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L PDI ES; 4 ('RTL') (line 463835)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2069, 0x002B };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L PDI ET; 4 ('RTL') (line 463836)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2069, 0x0023 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L PDI CS; 4 ('RTL') (line 463837)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2069, 0x002C };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L PDI NSM; 4 ('RTL') (line 463838)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2069, 0x0300 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L PDI B; 4 ('RTL') (line 463839)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2069, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L PDI S; 4 ('RTL') (line 463840)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2069, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_034)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // PDI L PDI WS; 4 ('RTL') (line 463841)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2069, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L PDI ON; 4 ('RTL') (line 463842)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2069, 0x0021 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L PDI LRI; 4 ('RTL') (line 463843)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2069, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L PDI RLI; 4 ('RTL') (line 463844)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2069, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L PDI FSI; 4 ('RTL') (line 463845)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2069, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI L PDI PDI; 4 ('RTL') (line 463846)
          std::vector<uint32_t> const cps = { 0x2069, 0x0041, 0x2069, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN R R; 5 ('auto') (line 463847)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x05BE, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN R R; 5 ('RTL') (line 463847)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x05BE, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN R AL; 5 ('auto') (line 463848)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x05BE, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN R AL; 5 ('RTL') (line 463848)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x05BE, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN R ES; 5 ('auto') (line 463849)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x05BE, 0x002B };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN R ES; 5 ('RTL') (line 463849)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x05BE, 0x002B };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN R ET; 5 ('auto') (line 463850)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x05BE, 0x0023 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN R ET; 5 ('RTL') (line 463850)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x05BE, 0x0023 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_035)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // PDI EN R CS; 5 ('auto') (line 463851)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x05BE, 0x002C };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN R CS; 5 ('RTL') (line 463851)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x05BE, 0x002C };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN R NSM; 5 ('auto') (line 463852)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x05BE, 0x0300 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN R NSM; 5 ('RTL') (line 463852)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x05BE, 0x0300 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN R B; 5 ('auto') (line 463853)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x05BE, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN R B; 5 ('RTL') (line 463853)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x05BE, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN R S; 5 ('auto') (line 463854)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x05BE, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN R S; 5 ('RTL') (line 463854)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x05BE, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN R WS; 5 ('auto') (line 463855)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x05BE, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN R WS; 5 ('RTL') (line 463855)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x05BE, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN R ON; 5 ('auto') (line 463856)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x05BE, 0x0021 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN R ON; 5 ('RTL') (line 463856)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x05BE, 0x0021 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN R LRI; 5 ('auto') (line 463857)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x05BE, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN R LRI; 5 ('RTL') (line 463857)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x05BE, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN R RLI; 5 ('auto') (line 463858)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x05BE, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN R RLI; 5 ('RTL') (line 463858)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x05BE, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN R FSI; 5 ('auto') (line 463859)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x05BE, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN R FSI; 5 ('RTL') (line 463859)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x05BE, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN R PDI; 5 ('auto') (line 463860)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x05BE, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN R PDI; 5 ('RTL') (line 463860)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x05BE, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_036)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // PDI EN AL R; 5 ('auto') (line 463861)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0608, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN AL R; 5 ('RTL') (line 463861)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0608, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN AL AL; 5 ('auto') (line 463862)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0608, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN AL AL; 5 ('RTL') (line 463862)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0608, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN AL ES; 5 ('auto') (line 463863)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0608, 0x002B };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN AL ES; 5 ('RTL') (line 463863)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0608, 0x002B };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN AL ET; 5 ('auto') (line 463864)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0608, 0x0023 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN AL ET; 5 ('RTL') (line 463864)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0608, 0x0023 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN AL CS; 5 ('auto') (line 463865)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0608, 0x002C };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN AL CS; 5 ('RTL') (line 463865)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0608, 0x002C };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN AL NSM; 5 ('auto') (line 463866)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0608, 0x0300 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN AL NSM; 5 ('RTL') (line 463866)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0608, 0x0300 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN AL B; 5 ('auto') (line 463867)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0608, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN AL B; 5 ('RTL') (line 463867)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0608, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN AL S; 5 ('auto') (line 463868)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0608, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN AL S; 5 ('RTL') (line 463868)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0608, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN AL WS; 5 ('auto') (line 463869)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0608, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN AL WS; 5 ('RTL') (line 463869)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0608, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN AL ON; 5 ('auto') (line 463870)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0608, 0x0021 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN AL ON; 5 ('RTL') (line 463870)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0608, 0x0021 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_037)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // PDI EN AL LRI; 5 ('auto') (line 463871)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0608, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN AL LRI; 5 ('RTL') (line 463871)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0608, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN AL RLI; 5 ('auto') (line 463872)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0608, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN AL RLI; 5 ('RTL') (line 463872)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0608, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN AL FSI; 5 ('auto') (line 463873)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0608, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN AL FSI; 5 ('RTL') (line 463873)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0608, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN AL PDI; 5 ('auto') (line 463874)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0608, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN AL PDI; 5 ('RTL') (line 463874)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0608, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN ES R; 5 ('auto') (line 463875)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x002B, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN ES R; 5 ('RTL') (line 463875)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x002B, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN ES AL; 5 ('auto') (line 463876)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x002B, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN ES AL; 5 ('RTL') (line 463876)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x002B, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN ES ES; 4 ('RTL') (line 463877)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x002B, 0x002B };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN ES ET; 4 ('RTL') (line 463878)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x002B, 0x0023 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN ES CS; 4 ('RTL') (line 463879)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x002B, 0x002C };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN ES NSM; 4 ('RTL') (line 463880)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x002B, 0x0300 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_038)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // PDI EN ES B; 4 ('RTL') (line 463881)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x002B, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN ES S; 4 ('RTL') (line 463882)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x002B, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN ES WS; 4 ('RTL') (line 463883)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x002B, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN ES ON; 4 ('RTL') (line 463884)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x002B, 0x0021 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN ES LRI; 4 ('RTL') (line 463885)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x002B, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN ES RLI; 4 ('RTL') (line 463886)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x002B, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN ES FSI; 4 ('RTL') (line 463887)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x002B, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN ES PDI; 4 ('RTL') (line 463888)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x002B, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN CS R; 5 ('auto') (line 463889)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x002C, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN CS R; 5 ('RTL') (line 463889)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x002C, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN CS AL; 5 ('auto') (line 463890)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x002C, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN CS AL; 5 ('RTL') (line 463890)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x002C, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_039)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // PDI EN CS ES; 4 ('RTL') (line 463891)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x002C, 0x002B };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN CS ET; 4 ('RTL') (line 463892)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x002C, 0x0023 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN CS CS; 4 ('RTL') (line 463893)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x002C, 0x002C };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN CS NSM; 4 ('RTL') (line 463894)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x002C, 0x0300 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN CS B; 4 ('RTL') (line 463895)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x002C, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN CS S; 4 ('RTL') (line 463896)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x002C, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN CS WS; 4 ('RTL') (line 463897)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x002C, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN CS ON; 4 ('RTL') (line 463898)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x002C, 0x0021 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN CS LRI; 4 ('RTL') (line 463899)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x002C, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN CS RLI; 4 ('RTL') (line 463900)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x002C, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_040)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // PDI EN CS FSI; 4 ('RTL') (line 463901)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x002C, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN CS PDI; 4 ('RTL') (line 463902)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x002C, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN S R; 5 ('auto') (line 463903)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0009, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN S R; 5 ('RTL') (line 463903)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0009, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN S AL; 5 ('auto') (line 463904)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0009, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN S AL; 5 ('RTL') (line 463904)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0009, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN S ES; 4 ('RTL') (line 463905)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0009, 0x002B };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN S ET; 4 ('RTL') (line 463906)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0009, 0x0023 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN S CS; 4 ('RTL') (line 463907)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0009, 0x002C };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN S NSM; 4 ('RTL') (line 463908)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0009, 0x0300 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN S B; 4 ('RTL') (line 463909)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0009, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN S S; 4 ('RTL') (line 463910)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0009, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_041)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // PDI EN S WS; 4 ('RTL') (line 463911)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0009, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN S ON; 4 ('RTL') (line 463912)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0009, 0x0021 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN S LRI; 4 ('RTL') (line 463913)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0009, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN S RLI; 4 ('RTL') (line 463914)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0009, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN S FSI; 4 ('RTL') (line 463915)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0009, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN S PDI; 4 ('RTL') (line 463916)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0009, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN WS R; 5 ('auto') (line 463917)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0020, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN WS R; 5 ('RTL') (line 463917)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0020, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN WS AL; 5 ('auto') (line 463918)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0020, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN WS AL; 5 ('RTL') (line 463918)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0020, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN WS ES; 4 ('RTL') (line 463919)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0020, 0x002B };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN WS ET; 4 ('RTL') (line 463920)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0020, 0x0023 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_042)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // PDI EN WS CS; 4 ('RTL') (line 463921)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0020, 0x002C };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN WS NSM; 4 ('RTL') (line 463922)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0020, 0x0300 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN WS B; 4 ('RTL') (line 463923)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0020, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN WS S; 4 ('RTL') (line 463924)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0020, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN WS WS; 4 ('RTL') (line 463925)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0020, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN WS ON; 4 ('RTL') (line 463926)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0020, 0x0021 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN WS LRI; 4 ('RTL') (line 463927)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0020, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN WS RLI; 4 ('RTL') (line 463928)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0020, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN WS FSI; 4 ('RTL') (line 463929)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0020, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN WS PDI; 4 ('RTL') (line 463930)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0020, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_043)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // PDI EN ON R; 5 ('auto') (line 463931)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0021, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN ON R; 5 ('RTL') (line 463931)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0021, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN ON AL; 5 ('auto') (line 463932)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0021, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN ON AL; 5 ('RTL') (line 463932)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0021, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN ON ES; 4 ('RTL') (line 463933)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0021, 0x002B };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN ON ET; 4 ('RTL') (line 463934)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0021, 0x0023 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN ON CS; 4 ('RTL') (line 463935)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0021, 0x002C };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN ON NSM; 4 ('RTL') (line 463936)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0021, 0x0300 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN ON B; 4 ('RTL') (line 463937)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0021, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN ON S; 4 ('RTL') (line 463938)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0021, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN ON WS; 4 ('RTL') (line 463939)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0021, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN ON ON; 4 ('RTL') (line 463940)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0021, 0x0021 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_044)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // PDI EN ON LRI; 4 ('RTL') (line 463941)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0021, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN ON RLI; 4 ('RTL') (line 463942)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0021, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN ON FSI; 4 ('RTL') (line 463943)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0021, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN ON PDI; 4 ('RTL') (line 463944)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x0021, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN LRI B; 4 ('RTL') (line 463945)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2066, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN LRI S; 4 ('RTL') (line 463946)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2066, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN LRI WS; 4 ('RTL') (line 463947)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2066, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN LRI LRI; 4 ('RTL') (line 463948)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2066, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN LRI RLI; 4 ('RTL') (line 463949)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2066, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN LRI FSI; 4 ('RTL') (line 463950)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2066, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_045)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // PDI EN LRI PDI; 4 ('RTL') (line 463951)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2066, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN RLI B; 4 ('RTL') (line 463952)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2067, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN RLI S; 4 ('RTL') (line 463953)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2067, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN RLI WS; 4 ('RTL') (line 463954)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2067, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN RLI LRI; 4 ('RTL') (line 463955)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2067, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN RLI RLI; 4 ('RTL') (line 463956)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2067, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN RLI FSI; 4 ('RTL') (line 463957)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2067, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN RLI PDI; 4 ('RTL') (line 463958)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2067, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN FSI B; 4 ('RTL') (line 463959)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2068, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN FSI S; 4 ('RTL') (line 463960)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2068, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_046)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // PDI EN FSI WS; 4 ('RTL') (line 463961)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2068, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN FSI LRI; 4 ('RTL') (line 463962)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2068, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN FSI RLI; 4 ('RTL') (line 463963)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2068, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN FSI FSI; 4 ('RTL') (line 463964)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2068, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN FSI PDI; 4 ('RTL') (line 463965)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2068, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN PDI R; 5 ('auto') (line 463966)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2069, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN PDI R; 5 ('RTL') (line 463966)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2069, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN PDI AL; 5 ('auto') (line 463967)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2069, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN PDI AL; 5 ('RTL') (line 463967)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2069, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN PDI ES; 4 ('RTL') (line 463968)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2069, 0x002B };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN PDI ET; 4 ('RTL') (line 463969)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2069, 0x0023 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN PDI CS; 4 ('RTL') (line 463970)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2069, 0x002C };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_047)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // PDI EN PDI NSM; 4 ('RTL') (line 463971)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2069, 0x0300 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN PDI B; 4 ('RTL') (line 463972)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2069, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN PDI S; 4 ('RTL') (line 463973)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2069, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN PDI WS; 4 ('RTL') (line 463974)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2069, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN PDI ON; 4 ('RTL') (line 463975)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2069, 0x0021 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN PDI LRI; 4 ('RTL') (line 463976)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2069, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN PDI RLI; 4 ('RTL') (line 463977)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2069, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN PDI FSI; 4 ('RTL') (line 463978)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2069, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI EN PDI PDI; 4 ('RTL') (line 463979)
          std::vector<uint32_t> const cps = { 0x2069, 0x0030, 0x2069, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN R R; 5 ('auto') (line 463980)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x05BE, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN R R; 5 ('RTL') (line 463980)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x05BE, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_048)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // PDI AN R AL; 5 ('auto') (line 463981)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x05BE, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN R AL; 5 ('RTL') (line 463981)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x05BE, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN R ES; 5 ('auto') (line 463982)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x05BE, 0x002B };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN R ES; 5 ('RTL') (line 463982)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x05BE, 0x002B };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN R ET; 5 ('auto') (line 463983)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x05BE, 0x0023 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN R ET; 5 ('RTL') (line 463983)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x05BE, 0x0023 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN R CS; 5 ('auto') (line 463984)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x05BE, 0x002C };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN R CS; 5 ('RTL') (line 463984)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x05BE, 0x002C };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN R NSM; 5 ('auto') (line 463985)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x05BE, 0x0300 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN R NSM; 5 ('RTL') (line 463985)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x05BE, 0x0300 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN R B; 5 ('auto') (line 463986)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x05BE, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN R B; 5 ('RTL') (line 463986)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x05BE, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN R S; 5 ('auto') (line 463987)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x05BE, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN R S; 5 ('RTL') (line 463987)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x05BE, 0x0009 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN R WS; 5 ('auto') (line 463988)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x05BE, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN R WS; 5 ('RTL') (line 463988)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x05BE, 0x0020 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN R ON; 5 ('auto') (line 463989)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x05BE, 0x0021 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN R ON; 5 ('RTL') (line 463989)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x05BE, 0x0021 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN R LRI; 5 ('auto') (line 463990)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x05BE, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN R LRI; 5 ('RTL') (line 463990)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x05BE, 0x2066 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  }
  
  TEST(bidi, bidi_927_049)
  {
  
      expected_levels = { 1, 2, 1, 1 };
      expected_reordered_indices = { 3, 2, 1, 0 };
  
      {
          // PDI AN R RLI; 5 ('auto') (line 463991)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x05BE, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN R RLI; 5 ('RTL') (line 463991)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x05BE, 0x2067 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN R FSI; 5 ('auto') (line 463992)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x05BE, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN R FSI; 5 ('RTL') (line 463992)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x05BE, 0x2068 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN R PDI; 5 ('auto') (line 463993)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x05BE, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN R PDI; 5 ('RTL') (line 463993)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x05BE, 0x2069 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN AL R; 5 ('auto') (line 463994)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x0608, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN AL R; 5 ('RTL') (line 463994)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x0608, 0x05BE };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN AL AL; 5 ('auto') (line 463995)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x0608, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN AL AL; 5 ('RTL') (line 463995)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x0608, 0x0608 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN AL ES; 5 ('auto') (line 463996)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x0608, 0x002B };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN AL ES; 5 ('RTL') (line 463996)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x0608, 0x002B };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN AL ET; 5 ('auto') (line 463997)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x0608, 0x0023 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN AL ET; 5 ('RTL') (line 463997)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x0608, 0x0023 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN AL CS; 5 ('auto') (line 463998)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x0608, 0x002C };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN AL CS; 5 ('RTL') (line 463998)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x0608, 0x002C };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN AL NSM; 5 ('auto') (line 463999)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x0608, 0x0300 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN AL NSM; 5 ('RTL') (line 463999)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x0608, 0x0300 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN AL B; 5 ('auto') (line 464000)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x0608, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), -1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), -1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, -1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
      {
          // PDI AN AL B; 5 ('RTL') (line 464000)
          std::vector<uint32_t> const cps = { 0x2069, 0x0660, 0x0608, 0x2029 };
          std::vector<int> const levels =
              bidi_levels(cps.begin(), cps.end(), 1);
          int i = 0;
          for (int l : expected_levels) {
              if (0 <= l) {
                  EXPECT_EQ(levels[i], l) << "i=" << i;
                  ++i;
              }
          }
          EXPECT_EQ((int)levels.size(), i);
  
          std::vector<int> const reordered =
              bidi_reordered_indices(cps.begin(), cps.end(), 1);
          i = 0;
          for (int idx : expected_reordered_indices) {
              // Skip FSI, LRI, RLI, and PDI.
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
  
          std::vector<int> reordered_2;
          for (auto subrange :
              boost::text::bidirectional_subranges(cps, 1)) {
              for (auto cp : subrange) {
                  reordered_2.push_back(cp);
              }
          }
          i = 0;
          for (int idx : expected_reordered_indices) {
              if (cps[idx] < 0x2066 || 0x2069 < cps[idx]) {
                  EXPECT_EQ(reordered_2[i], cps[idx])
                      << std::hex
                      << " 0x" << reordered_2[i]
                      << " 0x" << cps[idx]
                      << std::dec << " i=" << i;
              }
              ++i;
          }
          EXPECT_EQ(i, (int)reordered_2.size());
      }
  
  }
  