CTABLES: Fix treatment of string variables that differ past the first byte.
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 17 Apr 2023 23:08:56 +0000 (16:08 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Mon, 17 Apr 2023 23:10:50 +0000 (16:10 -0700)
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
tests/language/commands/ctables.at

index 224fe7ec60b0e3821dd1af79c60594fc547ef06d..36fcca64c7d1f81be1d5b5e78f91bcf1f2dab4f7 100644 (file)
@@ -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;
                         }
                     }
index 108e455e90fd683ba6592441de1f01a209bf3701..001eea6ea8139f964bc4ab378dc160ab8c2039af 100644 (file)
@@ -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 &notyes=EXPR(['No']+['DontKnow']+['Refused'])
+    /PCOMPUTE &notyes=EXPR(['No']+['DontKnow']+['NoAnswer'])
     /PPROPERTIES &notyes LABEL='Not Yes' HIDESOURCECATS=YES
     /TABLE licensed
-    /CATEGORIES VARIABLES=licensed ['Yes', &notyes, 'No', 'DontKnow', 'Refused'].
+    /CATEGORIES VARIABLES=licensed ['Yes', &notyes, 'No', 'DontKnow', 'NoAnswer'].
 CTABLES
-    /PCOMPUTE &notyes=EXPR(['DontKnow' THRU 'No'] + ['Refused'])
+    /PCOMPUTE &notyes=EXPR(['DontKnow' THRU 'No'] + ['NoAnswer'])
     /PPROPERTIES &notyes LABEL='Not Yes' HIDESOURCECATS=YES
     /TABLE licensed
-    /CATEGORIES VARIABLES=licensed ['Yes', &notyes, 'DontKnow' THRU 'No', 'Refused'].
+    /CATEGORIES VARIABLES=licensed ['Yes', &notyes, '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│
-╰────────────────┴─────╯
\95­â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94¬â\94\80â\94\80â\94\80â\94\80â\94\80â\95®
+│                 │Count│
\94\9câ\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94¼â\94\80â\94\80â\94\80â\94\80â\94\80â\94¤
+│licensed No      │  572│
+│         NoAnswer│   44│
+│         Yes     │ 6379│
+│         Total   │ 6995│
\95°â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94\80â\94´â\94\80â\94\80â\94\80â\94\80â\94\80â\95¯
 
       Custom Tables
 ╭────────────────┬─────╮