From 9dfbdc3c1782af1157cd0460403398d4c8ba2dfc Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 17 Apr 2023 16:08:56 -0700 Subject: [PATCH] CTABLES: Fix treatment of string variables that differ past the first byte. CTABLES display was treating string values with more than one byte as the same if they had the same first byte, because var_get_type() was confused with var_get_width(). (The former returns 0 for numeric and 1 for string and the latter returns 0 for numeric and string width for string.) Bug #64044. --- src/language/commands/ctables.c | 2 +- tests/language/commands/ctables.at | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/language/commands/ctables.c b/src/language/commands/ctables.c index 224fe7ec60..36fcca64c7 100644 --- a/src/language/commands/ctables.c +++ b/src/language/commands/ctables.c @@ -4765,7 +4765,7 @@ ctables_table_output (struct ctables *ct, struct ctables_table *t) && c->type != CCT_POSTCOMPUTE && !value_equal (&prev->axes[a].cvs[var_idx].value, &cell->axes[a].cvs[var_idx].value, - var_get_type (nest->vars[var_idx]))) + var_get_width (nest->vars[var_idx]))) break; } } diff --git a/tests/language/commands/ctables.at b/tests/language/commands/ctables.at index 108e455e90..001eea6ea8 100644 --- a/tests/language/commands/ctables.at +++ b/tests/language/commands/ctables.at @@ -947,8 +947,8 @@ AT_CHECK([ln $top_srcdir/tests/language/commands/nhtsa.sav . || cp $top_srcdir/t AT_DATA([ctables.sps], [[GET 'nhtsa.sav'. STRING licensed(A8). -MISSING VALUES licensed('DontKnow', 'Refused'). -RECODE qnd7a(1='Yes')(2='No')(3='DontKnow')(4='Refused') INTO licensed. +MISSING VALUES licensed('DontKnow', 'NoAnswer'). +RECODE qnd7a(1='Yes')(2='No')(3='DontKnow')(4='NoAnswer') INTO licensed. CTABLES /TABLE licensed. CTABLES /TABLE licensed [COUNT, TOTALS[COUNT, VALIDN]] /CATEGORIES VARIABLES=ALL TOTAL=YES MISSING=INCLUDE. CTABLES /TABLE licensed /CATEGORIES VARIABLES=licensed ['Yes', 'No'] TOTAL=YES. @@ -956,15 +956,15 @@ CTABLES /TABLE licensed /CATEGORIES VARIABLES=licensed ['Yes', 'No'] TOTAL=YES. CTABLES /TABLE licensed /CATEGORIES VARIABLES=licensed ['Yes', 'no'] TOTAL=YES. CTABLES /TABLE licensed /CATEGORIES VARIABLES=licensed ['No' THRU 'yes'] TOTAL=YES. CTABLES - /PCOMPUTE ¬yes=EXPR(['No']+['DontKnow']+['Refused']) + /PCOMPUTE ¬yes=EXPR(['No']+['DontKnow']+['NoAnswer']) /PPROPERTIES ¬yes LABEL='Not Yes' HIDESOURCECATS=YES /TABLE licensed - /CATEGORIES VARIABLES=licensed ['Yes', ¬yes, 'No', 'DontKnow', 'Refused']. + /CATEGORIES VARIABLES=licensed ['Yes', ¬yes, 'No', 'DontKnow', 'NoAnswer']. CTABLES - /PCOMPUTE ¬yes=EXPR(['DontKnow' THRU 'No'] + ['Refused']) + /PCOMPUTE ¬yes=EXPR(['DontKnow' THRU 'No'] + ['NoAnswer']) /PPROPERTIES ¬yes LABEL='Not Yes' HIDESOURCECATS=YES /TABLE licensed - /CATEGORIES VARIABLES=licensed ['Yes', ¬yes, 'DontKnow' THRU 'No', 'Refused']. + /CATEGORIES VARIABLES=licensed ['Yes', ¬yes, 'DontKnow' THRU 'No', 'NoAnswer']. ]]) AT_CHECK([pspp ctables.sps -O box=unicode -O width=80], [0], [dnl Custom Tables @@ -981,7 +981,7 @@ AT_CHECK([pspp ctables.sps -O box=unicode -O width=80], [0], [dnl ├─────────────────┼─────┼───────┤ │licensed DontKnow│ 4│ │ │ No │ 572│ │ -│ Refused │ 44│ │ +│ NoAnswer│ 44│ │ │ Yes │ 6379│ │ │ Total │ 6999│ 6951│ ╰─────────────────┴─────┴───────╯ @@ -1005,14 +1005,14 @@ AT_CHECK([pspp ctables.sps -O box=unicode -O width=80], [0], [dnl ╰──────────────┴─────╯ Custom Tables -╭────────────────┬─────╮ -│ │Count│ -├────────────────┼─────┤ -│licensed No │ 572│ -│ Refused│ 44│ -│ Yes │ 6379│ -│ Total │ 6995│ -╰────────────────┴─────╯ +╭─────────────────┬─────╮ +│ │Count│ +├─────────────────┼─────┤ +│licensed No │ 572│ +│ NoAnswer│ 44│ +│ Yes │ 6379│ +│ Total │ 6995│ +╰─────────────────┴─────╯ Custom Tables ╭────────────────┬─────╮ -- 2.30.2