OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1583 } | 1583 } |
1584 return false; | 1584 return false; |
1585 } | 1585 } |
1586 | 1586 |
1587 | 1587 |
1588 TEST(CharClassDifference) { | 1588 TEST(CharClassDifference) { |
1589 v8::internal::V8::Initialize(NULL); | 1589 v8::internal::V8::Initialize(NULL); |
1590 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); | 1590 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); |
1591 ZoneList<CharacterRange>* base = new ZoneList<CharacterRange>(1); | 1591 ZoneList<CharacterRange>* base = new ZoneList<CharacterRange>(1); |
1592 base->Add(CharacterRange::Everything()); | 1592 base->Add(CharacterRange::Everything()); |
1593 Vector<const uc16> overlay = CharacterRange::GetWordBounds(); | 1593 Vector<const int> overlay = CharacterRange::GetWordBounds(); |
1594 ZoneList<CharacterRange>* included = NULL; | 1594 ZoneList<CharacterRange>* included = NULL; |
1595 ZoneList<CharacterRange>* excluded = NULL; | 1595 ZoneList<CharacterRange>* excluded = NULL; |
1596 CharacterRange::Split(base, overlay, &included, &excluded); | 1596 CharacterRange::Split(base, overlay, &included, &excluded); |
1597 for (int i = 0; i < (1 << 16); i++) { | 1597 for (int i = 0; i < (1 << 16); i++) { |
1598 bool in_base = InClass(i, base); | 1598 bool in_base = InClass(i, base); |
1599 if (in_base) { | 1599 if (in_base) { |
1600 bool in_overlay = false; | 1600 bool in_overlay = false; |
1601 for (int j = 0; !in_overlay && j < overlay.length(); j += 2) { | 1601 for (int j = 0; !in_overlay && j < overlay.length(); j += 2) { |
1602 if (overlay[j] <= i && i <= overlay[j+1]) | 1602 if (overlay[j] <= i && i < overlay[j+1]) |
1603 in_overlay = true; | 1603 in_overlay = true; |
1604 } | 1604 } |
1605 CHECK_EQ(in_overlay, InClass(i, included)); | 1605 CHECK_EQ(in_overlay, InClass(i, included)); |
1606 CHECK_EQ(!in_overlay, InClass(i, excluded)); | 1606 CHECK_EQ(!in_overlay, InClass(i, excluded)); |
1607 } else { | 1607 } else { |
1608 CHECK(!InClass(i, included)); | 1608 CHECK(!InClass(i, included)); |
1609 CHECK(!InClass(i, excluded)); | 1609 CHECK(!InClass(i, excluded)); |
1610 } | 1610 } |
1611 } | 1611 } |
1612 } | 1612 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1665 list->Rewind(0); | 1665 list->Rewind(0); |
1666 list->Add(CharacterRange(10, 19)); | 1666 list->Add(CharacterRange(10, 19)); |
1667 list->Add(CharacterRange(21, 30)); | 1667 list->Add(CharacterRange(21, 30)); |
1668 list->Add(CharacterRange(20, 20)); | 1668 list->Add(CharacterRange(20, 20)); |
1669 set.Canonicalize(); | 1669 set.Canonicalize(); |
1670 ASSERT_EQ(1, list->length()); | 1670 ASSERT_EQ(1, list->length()); |
1671 ASSERT_EQ(10, list->at(0).from()); | 1671 ASSERT_EQ(10, list->at(0).from()); |
1672 ASSERT_EQ(30, list->at(0).to()); | 1672 ASSERT_EQ(30, list->at(0).to()); |
1673 } | 1673 } |
1674 | 1674 |
1675 // Checks whether a character is in the set represented by a list of ranges. | |
1676 static bool CharacterInSet(ZoneList<CharacterRange>* set, uc16 value) { | |
1677 for (int i = 0; i < set->length(); i++) { | |
1678 CharacterRange range = set->at(i); | |
1679 if (range.from() <= value && value <= range.to()) { | |
1680 return true; | |
1681 } | |
1682 } | |
1683 return false; | |
1684 } | |
1685 | 1675 |
1686 TEST(CharacterRangeMerge) { | 1676 TEST(CharacterRangeMerge) { |
1687 v8::internal::V8::Initialize(NULL); | 1677 v8::internal::V8::Initialize(NULL); |
1688 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); | 1678 ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); |
1689 ZoneList<CharacterRange> l1(4); | 1679 ZoneList<CharacterRange> l1(4); |
1690 ZoneList<CharacterRange> l2(4); | 1680 ZoneList<CharacterRange> l2(4); |
1691 // Create all combinations of intersections of ranges, both singletons and | 1681 // Create all combinations of intersections of ranges, both singletons and |
1692 // longer. | 1682 // longer. |
1693 | 1683 |
1694 int offset = 0; | 1684 int offset = 0; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1761 l2.Add(CharacterRange::Singleton(offset + 8)); | 1751 l2.Add(CharacterRange::Singleton(offset + 8)); |
1762 offset += 9; | 1752 offset += 9; |
1763 } | 1753 } |
1764 | 1754 |
1765 ASSERT(CharacterRange::IsCanonical(&l1)); | 1755 ASSERT(CharacterRange::IsCanonical(&l1)); |
1766 ASSERT(CharacterRange::IsCanonical(&l2)); | 1756 ASSERT(CharacterRange::IsCanonical(&l2)); |
1767 | 1757 |
1768 ZoneList<CharacterRange> first_only(4); | 1758 ZoneList<CharacterRange> first_only(4); |
1769 ZoneList<CharacterRange> second_only(4); | 1759 ZoneList<CharacterRange> second_only(4); |
1770 ZoneList<CharacterRange> both(4); | 1760 ZoneList<CharacterRange> both(4); |
1771 | |
1772 // Merge one direction. | |
1773 CharacterRange::Merge(&l1, &l2, &first_only, &second_only, &both); | |
1774 | |
1775 CHECK(CharacterRange::IsCanonical(&first_only)); | |
1776 CHECK(CharacterRange::IsCanonical(&second_only)); | |
1777 CHECK(CharacterRange::IsCanonical(&both)); | |
1778 | |
1779 for (uc16 i = 0; i < offset; i++) { | |
1780 bool in_first = CharacterInSet(&l1, i); | |
1781 bool in_second = CharacterInSet(&l2, i); | |
1782 CHECK((in_first && !in_second) == CharacterInSet(&first_only, i)); | |
1783 CHECK((!in_first && in_second) == CharacterInSet(&second_only, i)); | |
1784 CHECK((in_first && in_second) == CharacterInSet(&both, i)); | |
1785 } | |
1786 | |
1787 first_only.Clear(); | |
1788 second_only.Clear(); | |
1789 both.Clear(); | |
1790 | |
1791 // Merge other direction. | |
1792 CharacterRange::Merge(&l2, &l1, &second_only, &first_only, &both); | |
1793 | |
1794 CHECK(CharacterRange::IsCanonical(&first_only)); | |
1795 CHECK(CharacterRange::IsCanonical(&second_only)); | |
1796 CHECK(CharacterRange::IsCanonical(&both)); | |
1797 | |
1798 for (uc16 i = 0; i < offset; i++) { | |
1799 bool in_first = CharacterInSet(&l1, i); | |
1800 bool in_second = CharacterInSet(&l2, i); | |
1801 CHECK((in_first && !in_second) == CharacterInSet(&first_only, i)); | |
1802 CHECK((!in_first && in_second) == CharacterInSet(&second_only, i)); | |
1803 CHECK((in_first && in_second) == CharacterInSet(&both, i)); | |
1804 } | |
1805 | |
1806 first_only.Clear(); | |
1807 second_only.Clear(); | |
1808 both.Clear(); | |
1809 | |
1810 // Merge but don't record all combinations. | |
1811 CharacterRange::Merge(&l1, &l2, NULL, NULL, &both); | |
1812 | |
1813 CHECK(CharacterRange::IsCanonical(&both)); | |
1814 | |
1815 for (uc16 i = 0; i < offset; i++) { | |
1816 bool in_first = CharacterInSet(&l1, i); | |
1817 bool in_second = CharacterInSet(&l2, i); | |
1818 CHECK((in_first && in_second) == CharacterInSet(&both, i)); | |
1819 } | |
1820 | |
1821 // Merge into same set. | |
1822 ZoneList<CharacterRange> all(4); | |
1823 CharacterRange::Merge(&l1, &l2, &all, &all, &all); | |
1824 | |
1825 CHECK(CharacterRange::IsCanonical(&all)); | |
1826 | |
1827 for (uc16 i = 0; i < offset; i++) { | |
1828 bool in_first = CharacterInSet(&l1, i); | |
1829 bool in_second = CharacterInSet(&l2, i); | |
1830 CHECK((in_first || in_second) == CharacterInSet(&all, i)); | |
1831 } | |
1832 } | 1761 } |
1833 | 1762 |
1834 | 1763 |
1835 TEST(Graph) { | 1764 TEST(Graph) { |
1836 V8::Initialize(NULL); | 1765 V8::Initialize(NULL); |
1837 Execute("\\b\\w+\\b", false, true, true); | 1766 Execute("\\b\\w+\\b", false, true, true); |
1838 } | 1767 } |
OLD | NEW |