mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-17 02:37:25 +00:00
ICU-3042 Add enum API constants and tests for line break rule status values.
X-SVN-Rev: 13313
This commit is contained in:
parent
8add0376b7
commit
760c72a4df
3 changed files with 69 additions and 4 deletions
|
@ -241,6 +241,26 @@ typedef enum UWordBreak {
|
|||
UBRK_WORD_IDEO_LIMIT = 500
|
||||
} UWordBreak;
|
||||
|
||||
/**
|
||||
* Enum constants for the line break tags returned by getRuleStatus().
|
||||
* A range of values is defined for each category of
|
||||
* word, to allow for further subdivisions of a category in future releases.
|
||||
* Applications should check for tag values falling within the range, rather
|
||||
* than for single individual values.
|
||||
* @draft ICU 2.8
|
||||
*/
|
||||
typedef enum ULineBreakTag {
|
||||
/** Tag value for soft line breaks, positions at which a line break
|
||||
* is acceptable but not required */
|
||||
UBRK_LINE_SOFT = 0,
|
||||
/** Upper bound for soft line breaks. */
|
||||
UBRK_LINE_SOFT_LIMIT = 100,
|
||||
/** Tag value for a hard, or mandatory line break */
|
||||
UBRK_LINE_HARD = 100,
|
||||
/** Upper bound for hard line breaks. */
|
||||
UBRK_LINE_HARD_LIMIT = 200
|
||||
} ULineBreakTag;
|
||||
|
||||
|
||||
/**
|
||||
* Open a new UBreakIterator for locating text boundaries for a specified locale.
|
||||
|
|
|
@ -553,10 +553,10 @@ void RBBIAPITest::TestQuoteGrouping() {
|
|||
}
|
||||
|
||||
//
|
||||
// TestWordStatus
|
||||
// TestRuleStatus
|
||||
// Test word break rule status constants.
|
||||
//
|
||||
void RBBIAPITest::TestWordStatus() {
|
||||
void RBBIAPITest::TestRuleStatus() {
|
||||
|
||||
|
||||
UnicodeString testString1 = // Ideographic Katakana Hiragana
|
||||
|
@ -599,6 +599,51 @@ void RBBIAPITest::TestWordStatus() {
|
|||
}
|
||||
}
|
||||
delete bi;
|
||||
|
||||
// Now test line break status. This test mostly is to confirm that the status constants
|
||||
// are correctly declared in the header.
|
||||
testString1 = "test line. \n";
|
||||
// break type s s h
|
||||
|
||||
bi = (RuleBasedBreakIterator *)
|
||||
BreakIterator::createLineInstance(Locale::getEnglish(), status);
|
||||
if(U_FAILURE(status)) {
|
||||
errln("failed to create word break iterator.");
|
||||
} else {
|
||||
int32_t i = 0;
|
||||
int32_t pos, tag;
|
||||
UBool success;
|
||||
|
||||
bi->setText(testString1);
|
||||
pos = bi->current();
|
||||
tag = bi->getRuleStatus();
|
||||
for (i=0; i<3; i++) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
success = pos==0 && tag==UBRK_LINE_SOFT; break;
|
||||
case 1:
|
||||
success = pos==5 && tag==UBRK_LINE_SOFT; break;
|
||||
case 2:
|
||||
success = pos==12 && tag==UBRK_LINE_HARD; break;
|
||||
default:
|
||||
success = FALSE; break;
|
||||
}
|
||||
if (success == FALSE) {
|
||||
errln("Fail: incorrect word break status or position. i=%d, pos=%d, tag=%d",
|
||||
i, pos, tag);
|
||||
break;
|
||||
}
|
||||
pos = bi->next();
|
||||
tag = bi->getRuleStatus();
|
||||
}
|
||||
if (UBRK_LINE_SOFT >= UBRK_LINE_SOFT_LIMIT ||
|
||||
UBRK_LINE_HARD >= UBRK_LINE_HARD_LIMIT ||
|
||||
UBRK_LINE_HARD > UBRK_LINE_SOFT && UBRK_LINE_HARD < UBRK_LINE_SOFT_LIMIT ) {
|
||||
errln("UBRK_LINE_* constants from header are inconsistent.");
|
||||
}
|
||||
}
|
||||
delete bi;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -805,7 +850,7 @@ void RBBIAPITest::runIndexedTest( int32_t index, UBool exec, const char* &name,
|
|||
case 6: name = "extra"; break; /* Extra */
|
||||
case 7: name = "TestBuilder"; if (exec) TestBuilder(); break;
|
||||
case 8: name = "TestQuoteGrouping"; if (exec) TestQuoteGrouping(); break;
|
||||
case 9: name = "TestWordStatus"; if (exec) TestWordStatus(); break;
|
||||
case 9: name = "TestRuleStatus"; if (exec) TestRuleStatus(); break;
|
||||
case 10: name = "TestBug2190"; if (exec) TestBug2190(); break;
|
||||
case 11: name = "TestRegistration"; if (exec) TestRegistration(); break;
|
||||
case 12: name = "TestBoilerPlate"; if (exec) TestBoilerPlate(); break;
|
||||
|
|
|
@ -71,7 +71,7 @@ public:
|
|||
/**
|
||||
* Tests word break status returns.
|
||||
*/
|
||||
void TestWordStatus();
|
||||
void TestRuleStatus();
|
||||
|
||||
void TestBug2190();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue